if exercises

demand:

  • Specifies the test scores to determine student grades
  • 90-100 Excellent
  • 80-89 Good
  • 70-79 good
  • 60-69 pass
  • 60 The following fail

Code

public class Demo05IfElsePractise {
    public static void main(String[] args) {
        int score = 120;
        if (score >= 90 && score <= 100) {
            System.out.println("优秀");
        } else if (score >= 80 && score < 90) {
            System.out.println("好");
        } else if (score >= 70 && score < 80) {
            System.out.println("良");
        } else if(Score> = 60 && Score <70 ) { 
            System.out.println ( "pass" ); 
        } the else  IF (Score> = 0 && Score <60 ) { 
            System.out.println ( "fail" ); 
        } the else { // separate treatment pathological case outside the boundary 
            System.out.println ( "data error" ); 
        } 
    } 
}

demand

Ternary operator and if-else statement standards were achieved: maximum value among the two numbers

public  class Demo06Max {
     public  static  void main (String [] args) {
         int A = 105 ;
         int B = 20 is ; 

        // first the ternary operator 
        int MAX1 = A> B? A: B; 
        System.out.println ( "Max:" MAX1 +); // max: 105 

        // used today if statement 
        int MAX2;
         if (a> B) { 
            MAX2 = a; 
        } the else { 
            MAX2 = B; 
        } 

        System.out.println ("Max:" + MAX2); // max: 105 
    } 
}

 

Guess you like

Origin www.cnblogs.com/wurengen/p/11020660.html