• 06java基础知识


    1.顺序结构

    java的基本结构就是顺序结构,除非特别指明,否则就按照代码的顺序从前到后一句一句的执行。

    2.选择结构

    • if单选择结构

    if(布尔表达式){

    //如果布尔表达式为true,将执行这里面的语句

    }

     import java.util.Scanner;
     
     public class scanner_pro2 {
         public static void main(String[] args) {
             Scanner scanner=new Scanner(System.in);
             String s=scanner.nextLine();
             if(s.equals("fadadefan")){
                 System.out.println("The String you have input is fadadefan");
            }
             System.out.println("End");
             scanner.close();
        }
     }
    • if双选择结构

     import java.util.Scanner;
     
     public class scanner_pro2 {
         public static void main(String[] args) {      
      Scanner scanner = new Scanner(System.in);
             System.out.println("Please insert you salary:");
             int money=scanner.nextInt();
             if (money>100){
                 System.out.println("You are rich!");
            } else {
                 System.out.println("You are poor!");
            }
             scanner.close();
        }
     }
    • if多选择结构

    • 嵌套的if结构

     switch多选择结构

     

     import java.util.Scanner;
     
     public class switchDemo {
         public static void main(String[] args) {
             char selection='B';
             switch (selection){
                 case 'A':
                     System.out.println("The selection is A");
                    // break;//case穿透现象
                 case 'B':
                     System.out.println("The selection is B");
                    // break;
                 case 'C':
                     System.out.println("The selection is C");
                    // break;
                 case 'D':
                     System.out.println("The selection is D");
                     //break;
                 default:
                     System.out.println("You have no idea!");
            }
      scanner.close();
        }
     }
     

    这就是case穿透现象,没有break,匹配的选项之后的选项的结果都会输出,所以任何时候都要把对应的break加上

    • 测试实例

     import java.util.Scanner;
     
     public class switchDemo {
         public static void main(String[] args) {
     //       String selection;
             System.out.println("Please insert you choice:");
             Scanner scanner=new Scanner(System.in);
     //       selection = scanner.next();
             char b=scanner.next().charAt(0);//用字符串为跳板,获取字符串的第一个字符
             switch (b){
                 case 'A':
                     System.out.println("The selection is A");
                     break;
                 case 'B':
                     System.out.println("The selection is B");
                     break;
                 case 'C':
                     System.out.println("The selection is C");
                     break;
                 case 'D':
                     System.out.println("The selection is D");
                     break;
                 default:
                     System.out.println("You have no idea!");
            }
              scanner.close();
        }
     }

    使用IDEA进行程序的反编译

    IDEA成功运行一个程序之后会产生相应的.class文件,我们打开相应的.class文件就能看到反编译之后的字节码文件

    新版IDEA可以直接打开out文件夹查看.class文件,如果IDEA面板上没有out文件夹,可以使用如下方法进入:

    1. 进入project structure,然后复制project compiler output的文件夹路径

    1. 进入此路径找到相应的.class 文件,拷贝到对应的.java文件夹中,然后双击打开即可:

    自学java,请多多指教!
  • 相关阅读:
    我喜欢网站
    我喜欢网站
    wpf Textbox 回车就换行
    wpf Textbox 回车就换行
    arguments.callee的用法
    与您分享
    Examples — guidata v1.5.1 documentation
    与您分享
    与您分享
    hierarchical clustering algorithms
  • 原文地址:https://www.cnblogs.com/fanfada/p/13726872.html
Copyright © 2020-2023  润新知