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);
    }
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值