Fifth java jobs

1. Were used for loops, while loops, do require that all cycle integer divisible by 3 and between 1 and 100

package one;
public class one1 {
    public static void main(String[] args) {
        int sum = 0;
        for(int i =1; i <=100; i++) {
            if(i %3 == 0) {
            sum += i;
        }
    }
        System.out.println ( "be the number divisible by 3 and between 1-100:" + SUM);
}
}

package one;
public class one1 {
    public static void main(String[] args) {
        int i = 1;
        int sum = 0;
        while(i < 101) {
            i++;
            if(i %3 == 0) {
                sum += i;
            }
        }
        System.out.println ( "divide by 3 and 1-100 are:" + SUM);
    }
}

package one;
public class one1 {
    public static void main(String[] args) {
        int i = 0;
        int sum = 1;
        do {
            i++;
            if(i %3 == 0){
                sum += i;
            }
        }while(i < 101);
        System.out.println ( "number divisible by 3 and 1-100 can be:" + SUM);
    }
}

2. Output number between 0-9, but does not include 5. (Knowledge: conditions Loops

package one;
public class one1 {
    public static void main(String[] args) {
        int i;
        for(i = 1;i < 10; i++ ) {
            if(i!=5) {
        System.out.println( i );
            } else {
            }
            }
    }
}

3. Write a program, find the integer n factorial, for example, 5 factorial is 1 * 2 * 3 * 4 * 5 (knowledge: loop

package one;
import java.util.*;
public class one1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i =sc.nextInt();
        int sum =1;
        for(int x=1; x <= i; x++) {
            sum=sum * x;
        }
        System.out.println( sum);
    }
}

4. Write a program, enter any student achievement, if the input is not legitimate (<0 or> 100), suggesting that input errors, re-enter until the input end of the legal procedure (knowledge: Loops)

package one;
import java.util.*;
public class one1 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        for(int i = 0; ; i++) {
            System.out.println ( "Please enter student achievement:" );
             int Score = input.nextInt ();
             IF (Score <0 || Score> 100 ) {
                System.out.println ( "input error, please re-enter:" );
            } else {
                System.out.println ( "The student achievement is:" + Score);
                 BREAK ;
            }
        }
    }
}

 

5. Suppose a staff this year's annual salary is 30,000 yuan, the annual salary of the annual growth rate of 6%. Write a Java application to calculate the employee's annual salary after 10 years, and counting the next 10 years (counting from the year) of total income.

package one;
import java.util.*;
public class one1 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        double salary = 0;
        double tenyear = 30000;
        for(int i = 1; i <=10; i++){
            tenyear + = tenyear * 0:06 ;
            salary += tenyear;
        }
        System.out.println ( "After ten years the annual salary of a programmer:" + tenyear);
        System.out.println ( "Total revenue for the programmer for the next decade:" + salary);
    }
}

 

Guess you like

Origin www.cnblogs.com/zjzj123/p/12597859.html