cyany

if

int x = 10;

      if( x < 20 ) {
         System.out.print("This is if statement");
      }

if else

int x = 30;

      if( x < 20 ) {
         System.out.print("This is if statement");
      }else {
         System.out.print("This is else statement");
      }


int x = 30;

      if( x == 10 ) {
         System.out.print("Value of X is 10");
      }else if( x == 20 ) {
         System.out.print("Value of X is 20");
      }else if( x == 30 ) {
         System.out.print("Value of X is 30");
      }else {
         System.out.print("This is else statement");
      }


嵌套if

int x = 30;
      int y = 10;

      if( x == 30 ) {
         if( y == 10 ) {
            System.out.print("X = 30 and Y = 10");
         }
      }

switch

char grade = \'C\';

      switch(grade) {
         case \'A\' :
            System.out.println("Excellent!"); 
            break;
         case \'B\' :
         case \'C\' :
            System.out.println("Well done");
            break;
         case \'D\' :
            System.out.println("You passed");
         case \'F\' :
            System.out.println("Better try again");
            break;
         default :
            System.out.println("Invalid grade");
      }
      System.out.println("Your grade is " + grade);

三元运算符
Exp1 ? Exp2 : Exp3;

分类:

技术点:

相关文章:

  • 2021-12-30
  • 2021-07-31
  • 2022-01-29
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-11
  • 2021-12-27
  • 2022-02-25
  • 2021-12-16
  • 2021-06-16
  • 2021-05-27
  • 2021-05-10
相关资源
相似解决方案