首页 > 其他 > 详细

If,Switch顺序选择结构以及反编译

时间:2021-04-25 23:31:54      阅读:24      评论:0      收藏:0      [点我收藏+]

选择结构

if结构

  1. if语句分为单if选择结构( if() ),if双选择结构( if(){} else{} ),if多选择结构( if(){} else if(){} else if(){} else ),嵌套的if结构( if(){ if(){} } else{} )

  2. if语句至多有1个else,else在所有的else if语句的后面,可以有若干个else if语句,一旦其中一个else if语句为true,其他的else if语句和else都不执行。

package com.peng.struct;
?
import java.util.Scanner;
?
public class IfStruct {
   public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
       System.out.println("请输入:");
       String s = scanner.nextLine();
       int score=scanner.nextInt();
?
       // equals:判断字符串是否相等
       if (s.equals("Hello"))
      {
           System.out.println(s);
      }
?
       if (s.equals("晖狗"))
      {
           System.out.println("在睡觉");
      }else
      {
           System.out.println("你好");
      }
?
       if (score==100)
      {
           System.out.println("太棒了,满分欸");
      }else if (score<100 && score>=85)
      {
           System.out.println("很优秀,继续保持");
      }else if (score<85 && score>=70)
      {
           System.out.println("良好,要加油");
      }else if (score<70 && score>=60)
      {
           System.out.println("及格了,要想上看哦");
      }else if (score<60 && score>=0)
      {
           System.out.println("可惜了,没有及格");
      }
       else
      {
           System.out.println("好像有点不合理");
      }
       System.out.println("拜比");
       scanner.close();
  }
}
?

 


Switch结构

  1. case具有穿透性,switch是匹配一个具体的值,最好在每一个case之后都加上break

package com.peng.struct;
?
import java.util.Scanner;
?
public class SwichStruct {
   public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
       String friend=scanner.nextLine();
?
       switch (friend){
           case "罗颖":
               System.out.println("人民教师");
?
           case "崔雪莲":
               System.out.println("小女孩");
               break;
           case "许嵩雪":
               System.out.println("总将成为一位画家");
           default:
               System.out.println("还什么都没成为");
      }
  }
}
?

 

反编译

反编译 java---class(字节码文件---看不懂的乱码)---反编译为java程序(使用IDEA就可以反编译)

  1. 在项目结构(Project Sturcture)中找到项目编译之后输出的路径,我的为D:\JavaSE\out,并打开。

  2. 在文件中可以找到自己所写的文件,但是class文件直接打开都是看不懂的乱码,直接拷贝进IDEA中可能会报错,所以在IEDA中选择打开文件夹(右键找到Open in然后选择Explorer。

  3. 把D:\JavaSE\out中的class文件丢到这些java文件中打开。

  4. 过来之后开头会有01显示,双击打开这个就是反编译之后的文件

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
?
package com.peng.struct;
?
import java.util.Scanner;
?
public class SwichStruct {
   public SwichStruct() {
  }
?
   public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
       String friend = scanner.nextLine();
       byte var4 = -1;
       switch(friend.hashCode()) {
       case 1049631:
           if (friend.equals("罗颖")) {
               var4 = 0;
          }
           break;
       case 24130076:
           if (friend.equals("崔雪莲")) {
               var4 = 1;
          }
           break;
       case 35152985:
           if (friend.equals("许嵩雪")) {
               var4 = 2;
          }
      }
?
       switch(var4) {
       case 0:
           System.out.println("人民教师");
       case 1:
           System.out.println("小女孩");
           break;
       case 2:
           System.out.println("总将成为一位画家");
       default:
           System.out.println("还什么都没成为");
      }
?
  }
}
?

 

If,Switch顺序选择结构以及反编译

原文:https://www.cnblogs.com/Share-my-life/p/14701683.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!