Java machines work on the fourth week

1. programming, the value of the input variable x, if it is 1, output x = 1, if it is 5, the output x = 5, if it is 10, x = 10 outputs, in addition to the above several values ​​are output x = none. (Knowledge: if conditional statement)

Package BaO;
 / * . programming, the value of the input variable x, if it is 1, output x = 1, if it is 5, the output 5 = x, 
 * if it is 10, x = 10 outputs, in addition to the above several values are = none output X   * / 
Import java.util.Scanner;
 public  class Lei {
     public  static  void main (String [] args) { 
        Scanner iNPUT = new new Scanner (the System.in); 
        System.out.println ( "Please enter any number " );
             Double X = input.nextDouble ();
             IF (X ==. 1 ) { 
                    System.out.println ( " X =. 1 " ); 
            } the else  IF (X ==. 5) {
                System.out.println("x=5");
            }else if(x==10) {
                System.out.println("x=10");
            }else
                System.out.println("x=none");
    }
}
            
            

 

2. To achieve the first question with a switch structure

Package BaO;
 / * programming, the value of the input variable x, if it is 1, output x = 1, if it is 5, the output x = 5, if it is 10, output 10 = x, 
 * addition to the above several values are output x = none. (Knowledge: if conditional statement)   * / 
Import java.util.Scanner;
 public  class Lei {
     public  static  void main (String [] args) { 
        Scanner INPUT = new new Scanner (the System.in); 
        System.out.println ( " enter any number " ); 
        Scanner SC = new new Scanner (the System.in);
         int I = input.nextInt ();
         Switch (I) {
             Case . 1 :
                System.out.println("x="+i);
                break;
            case 5:
                System.out.println("x="+i);
                break;
            case 10:
                System.out.println("x="+i);
                break;
            default:
                System.out.println("x=none");
                break;
        }
 
    }
}
            
            

 

Determining whether a number is 3. 5 and 6 can be simultaneously divisible (5 and 6 can be divisible print), or can only be divisible by 5 (5 be divisible print), or can only be divisible by 6, (6 can print divisible ), can not be divisible by 5 or 6, (printing can not be divisible by 5 or 6)

Package BaO;
 / * determining whether a number can be 5 and 6 simultaneously divisible (5 and 6 can be divisible print), or can only be divisible by 5 (5 be divisible print), 
 * 6, or can only be divisible (print be divisible by 6), can not be divisible by 5 or 6, (printing can not be divisible by 5 or 6)   * / 
Import java.util.Scanner;
 public  class Lei {
     public  static  void main (String [] args) { 
        Scanner INPUT = new new Scanner (the System.in); 
        System.out.println ( "Please enter any number" );
             Double X = input.nextDouble ();
             IF (X == 0 &&%. 5%. 6 X == 0 ) { 
                    the System.out. the println ( "be divisible by 6 and 5" ); 
            } the else IF (!% X 5% X == 0 &&. 6 = 0 ) { 
                System.out.println ( "be divisible by 5" ); 
            } the else  IF (! = 0 && X X 5%. 6% == 0 ) { 
                the System.out. the println ( "be divisible by 6" ); 
            } the else 
                System.out.println ( "can not be divisible by 5 or 6" ); 
    } 
}
            
            

 

4. Enter a score of 0 to 100, if not between 0 to 100, the print score is invalid, printing A (90-100), B (80-89) according to grade scores, C, D, E (knowledge: Condition statement if elseif)

Package BaO;
 / * input a score of 0 to 100, 0 to 100 if it is not, the print score is invalid, 
 * Print A (90-100) The score levels, B (80-89), C, D, E ( knowledge: ELSEIF conditional statement IF)   * / 
Import java.util.Scanner;
 public  class Lei {
     public  static  void main (String [] args) { 
        Scanner INPUT = new new Scanner (the System.in); 
        System.out.println ( " enter any number " );
             Double X = input.nextDouble ();
             IF (X> 100 X || <0 ) { 
                System.out.println ( " input error " ); 
            } the else  IF(x>=90&&x<=100){
                    System.out.println("A");
            }else if(x>=80&&x<=89) {
                System.out.println("B");
            }else if(x>=70&&x<=79) {
                System.out.println("C");
            }else if(x>=60&&x<=69) {
                System.out.println("D");
            }else if (x>=50&&x<=59) {
                System.out.println("E");
            }else
                System.out.println(x);
    }
}
            
            

 

5. Enter three integers x, y, z, please small to large number of these three outputs (knowledge: conditional statements)

Package BaO;
 / * Java three integers input from the console, to achieve the output in order of size   * / 
Import java.util.Scanner;
 public  class Lei {
     public  static  void main (String [] args) { 
        Scanner INPUT = new new Scanner (the System .in); 
        System.out.println ( "Please enter any three integers" );
             int A = input.nextInt ();
             int B = input.nextInt ();
             int C = input.nextInt ();
             IF (A > B) {
                 IF (B> C) {
                    System.out.println ( "descending order of:" + A + "," + B + "," + C); 
                } the else  IF (C> A) { 
                    System.out.println ( "press from order of small to large: "C + +", "+ A +", "+ B); 
                } the else { 
                    System.out.println ( " descending order of: "+ a +", " + c + "," + B); 
                } 
            } the else {
                 IF (C < A) { 
                    System.out.println ( "descending order of:" + b + "," + a + ","+ c);
                }else if(c >B) { 
                    System.out.println ( "descending order of:" C + + "," + B + "," + A); 
                } the else { 
                    System.out.println ( "descending order of: "+ + B", "C + +", "+ A); 
                } 
            } 
        } 
    }

 

Guess you like

Origin www.cnblogs.com/student-yyh/p/12573248.html