OOP(JAVA)-Lab0-2023/9/5

第一次上机

package Lab;

import java.util.Scanner;

public class Lab00 {
    //boolean a;
    static void print(String s) {
        System.out.println(s);
    }
    static boolean test1(int val) {
        print("1");
        return val < 1;
    }
    static boolean test2(int val) {
        print("2");
        return val < 2;
    }
    static boolean test3(int val) {
        print("3");
        return val < 3;
    }
    public static void main1(String[] args) {
        boolean b = test1(0) && test2(2) && test3(2);
        print("b is " + b);
    }
    public static void main2(String[] args) {
        //System.out.println("Hello World!");
        /*int x=0;
        while(true){
            x++;
            if(x>100){
                System.out.println("get 100");
                System.exit(0);
            }
        }*/
        /*String str="Hello world!";
        System.out.println(str);*/
        /*Scanner in=new Scanner(System.in);
        String argStr;
        while(true){
            argStr = in.nextLine();
            if (argStr.length() == 0) {
                System.exit(0);
            }
        }*/
        /*System.out.println("Hello world!");
        int a=1;
        a=a+1;
        a=a+2;
        System.out.println("a is "+a);
        a=a+3;
        a=a+4;
        System.out.println("a is "+a);*/
        /*int a=6;
        double b=0.2;
        double c=1.6;
        String str1 ="Hello world";
        String str = new String("字符串不是基本数据结构");
        System.out.println("a= "+a);
        System.out.println("b+c= "+(b+c));
        System.out.println("b+c= "+b+c);
        System.out.println(str);
        System.out.println(str1);*/
        /*byte b=0x55;
        boolean B=true;
        short s=0x55ff;
        int i=1000000;
        long l=0xffffL;
        char c ='c';
        float f=0.23F;
        double d=0.7E-3;
        String S = "This is a string";
        System.out.println("字节型变量 b = " + b);
        System.out.println("短整型变量 s = " + s);
        System.out.println("整型变量 i = " + i);
        System.out.println("长整型变量 l = " + l);
        System.out.println("字符型变量 c = " + c);
        System.out.println("浮点型变量 f = " + f);
        System.out.println("双精度变量 d = " + d);
        System.out.println("布尔型变量 B = " + B);
        System.out.println("字符串对象 S = " + S);*/
        /*Lab00 test=new Lab00();
        System.out.println("a= "+test.a);*/
        /*//三元运算符
        double temp, max, min;
        double d1 = 1, d2 = -9.9, d3 = 96.9;
        temp = d1 > d2 ? d1 : d2;
        temp = temp > d3 ? temp : d3;
        max = temp;
        temp = d1 < d2 ? d1 : d2;
        temp = temp < d3 ? temp : d3;
        min = temp;
        System.out.println("max= " + max);
        System.out.println("min= " + min);*/
        //短路  把main1和main交换

    }
    int a = 10;
    double b=20;
    /*public static void main(String[] args){
        Lab00 globalVal=new Lab00();
        // System.out.println("全局变量 a = " +a); 错误写法
        System.out.println("全局变量 a= "+globalVal.a);
        globalVal.changeGlobal();
        System.out.println("全局变量变化后a= "+ globalVal.a);
    }
    public void changeGlobal(){
        System.out.println("在 print() 中, 全局变量 a = " + a + ", b = " + b);
        a = 30;
        System.out.println("在 print() 中, 全局变量 a = " + a + ", b = " + b);
    }*/
    public static void main(String[] args){
        Lab00 localVal = new Lab00();
        localVal.change();
    }
    public void change() {
        int a = 10; // 局部变量,下同
        double b = 20;
        System.out.println("在 print() 中的局部变量 a = " + a + ", b = " + b);
        a = 30;
        System.out.println("在 print() 中的局部变量 a = " + a + ", b = " + b);
    }
}






你可能感兴趣的:(java,开发语言,算法,maven,intellij-idea)