2020.3.30 fourth java jobs

1. They were used for loops, while loops, do require that all cycles can be an integer divisible by 3 and between 1 and 100.

for:

Package com.itheima01; 

Import java.util.Scanner; 

public  class the HelloWorld {
      public  static  void main (String [] args) {
          int X =. 1, SUM = 0 ;
             for (; X <= 100; X ++ ) {
                 IF (X 3 == 0% ) { 
                SUM + = X ; 
                } 
            } 
                System.out.println ( "all numbers between 1 and 100 can be divided by 3 and is" + SUM); 
            }             
}

while:

Package com.itheima01; 

Import java.util.Scanner; 

public  class the HelloWorld {
     public  static  void main (String [] args) {
         int X =. 1, SUM = 0 ;
         the while (X <= 100 ) {
             IF (X =. 3% 0 = ) { 
                SUM + = X;             
            } 
            X ++ ; 
        }     
        System.out.println ( "all numbers between 1 and 100 can be divided by 3 and is" + SUM); 
    }         
}

do:

package com.itheima01;

import java.util.Scanner;

public class HelloWorld {
    public static void main(String[] args){
        int x=1;
        int sum=0;
        do{
            if(x%3==0){
                sum+=x;
                x++;
            }else{
                x++;
            }
        }while(x<=100);
        System.out.println("All numbers between 1 and 100 can be divided by 3 and is" + SUM); 
    }   
}

2. Output a number between 0-9, but does not include 5.

package com.itheima01;

import java.util.Scanner;

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

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

Package com.itheima01; 

Import java.util.Scanner; 

public  class the HelloWorld {
     public  static  void main (String [] args) {
                 int SUM =. 1 ;
                 int X; 
                Scanner SC = new new Scanner (the System.in); 
                the System.out. the println ( "Please enter an integer:" );
                 int J = sc.nextInt ();
                 for (X =. 1; X <= J; X ++ ) 
                { 
                    SUM = SUM * X; 
                }
                System.out.println ( "factorial is:" + SUM); 
    } 
}

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

Package com.itheima01; 

Import java.util.Scanner; 

public  class the HelloWorld {
     public  static  void main (String [] args) { 
        Scanner INPUT = new new Scanner (the System.in); 
        System.out.println ( "Enter Results:" );
         int X = input.nextInt ();
         the while (X> 100 X || <0 ) { 
            System.out.println ( "the error number, please re-enter" ); 
            X = input.nextInt (); 
        } 
        the System .out.println ( "score" + X); 
    } 
}

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 com.itheima01;

import java.util.Scanner;

public class HelloWorld {
      public static void main(String[] srgs) {
            double z=30000;
            double y=1;
            double growth_rate=0.06;
            for(;y<=10;y++) {
                z=z*(1+growth_rate);
            }
            System.out.print("十年后年薪为");
            System.out.println(String.format("%.2f",z));
        }
}

 

Guess you like

Origin www.cnblogs.com/megumin/p/12606268.html