Java零基础入门:运算符练习

Java零基础入门:运算符练习,第1张

之前练习的库存:

public class Test01 {
    public static void main(String[] args) {
        int x = 10;
        int a = x + x++;//a=10+10,该代码执行结束,x=11;
        //++X:先自加再取值,X++先取值再自加
        //a先取x+x的值,x再自加值
        System.out.println("x="+a);//20
        System.out.println("x="+x);//11

        int b = x+ ++x;//b=11+12,该代码执行结束,x=12;
        System.out.println("b="+b);//23
        System.out.println("x="+x);//12

        int c = x + x--;//c=12+12,该代码执行结束,x=11
        System.out.println("c="+c);//24
        System.out.println("x="+x);//11

        int d = x + --x;//d=11+10,该代码执行结束,x=10
        System.out.println("d="+d);//21
        System.out.println("x="+x);//10
    }
}

public class Test02 {
    public static void main(String[] args){
        int a = 15;
        int b = 2;
        double c = 2;
        System.out.println(a+"/"+b+"="+(a/b));
        System.out.println(a+"%"+b+"="+(a%b));
        System.out.println(a+"/"+c+"="+(a/c));
        System.out.println(a+"%"+b+"="+(a%b));

    }
}

public class ZuoyeTest03 {
     public static void main(String[] ages){
         boolean x,y,z;
         int a = 15;
         int b = 2;
         x = a > b;
         y = a < b;
         z = a != b;
         System.out.println("x="+x);
         System.out.println("y="+y);
         System.out.println("z="+z);

     }
}

public class Test04 {
    public static void main(String[] args){
        boolean raining = false;
        if(raining){
            System.out.println("外面下雨了,出门记得带一把伞哦!");

        }else{
            System.out.println("天气不错哦!");

        }
        boolean eatFull = true;
        if(eatFull){
            System.out.println("吃的好饱啊!");
        }else{
            System.out.println("还没有吃饱,再来份米饭!");

        }
        boolean sex = true;
        if(sex){
            System.out.println("男");
            System.out.println("Hello world!");
        }
        else{
            System.out.println("女");

        }
        java.util.Scanner scan = new java.util.Scanner(System.in);
        System.out.print("请输入数字;");
        int i = scan.nextInt();
        if(i==1){
            System.out.println("性别:男");

        }else if(i==0){
            System.out.println("性别:女");
        }else{
            System.out.println("对不起,你输入不合法!");
        }
        System.out.print("输入考试成绩:");
        int score = scan.nextInt();
        String grade = "大笨蛋";
        if(score < 0 || score > 100){
            grade = "对不起,您输入的成绩不合法!";
        }else if(score >= 90){
            grade = "优秀";
        }else if(score >= 80){
            grade = "良好";
        }else if(score >= 70){
            grade = "中等";
        }else if(score >= 60){
            grade = "及格";
        }
        System.out.println("成绩等级:" + grade);
    }
}

public class Test05 {
    public static void main(String[] args){
        java.util.Scanner scann = new java.util.Scanner(System.in);
        System.out.print("请输入天气指数,1 表示下雨天,0 表示晴天:");
        int weather = scann.nextInt();
        if(weather == 1){
            System.out.print("请再输入您的性别,1 表示男,0 表示女:");
            int sex = scann.nextInt();
            if(sex == 0){
                System.out.println("女士,外面下雨了,您需要带一把小花伞");
            }else if(sex == 1){
                System.out.println("哥们,外面下雨了,您需要带一把大黑伞");
            }else{
                System.out.println("对不起,您输入性别参数出错了!");
            }
        }else if(weather == 0){
            System.out.println("走起,一起出去玩耍喽!");
        }else{
            System.out.println("对不起,您输入天气参数出错了!");
        }
    }
}
public class homework01 {
    public static void main(String[] args){
        int i = 5;
        int j = 5;
        int m = 5;
        int n = 5;

        i++;//i=5,该代码执行结束后,i=6;
        j = j + 1;//j=6
        m--;//m=5,该代码执行结束之后,m=4;
        n = n - 1;//n=4;
        System.out.println(i);//i=6
        System.out.println(i++);//i=6,该代码执行结束后,i=7
        System.out.println(++i);//i=8,该代码执行结束后,i=8
        System.out.println(i--);//i=8,该代码执行结束后,i=7
        System.out.println();
        System.out.println(j);
        System.out.println(j++);
        System.out.println(j--);
        System.out.println(--j);
        System.out.println();
        System.out.println(m);
        System.out.println(n);
    }
}

public class homework02 {
    public static void main(String[] args) {
        for (int i = 10; i > 0; i--) {
            System.out.println("i = " + i);
        }
        System.out.println("-------------分割线---------------");
        for (int i = 10; i > 0; i -= 2) {
            System.out.println("i = " + i);
        }
        System.out.println("-------------分割线---------------");
        for (int i = 100; i >= 10; i /= 3) {
            System.out.println("i = " + i);
        }

    }
}

public class homework04 {
    public static void main(String[] args){
        for(int i = 1;i <= 5; i++){
            System.out.print("i = " + i + ",");
        }
        System.out.println();

         for(int j=1;j<=2;j++){
             System.out.print("j="+j+",");
         }
         System.out.println();
         for(int j = 1;j <= 2;j++){
             for(int i = 1;i <= 5;i++){
                 System.out.print("i="+i+",");
             }
         }
    }

}

public class homeword5 {
    public static void main(String[] args){
        for(int i = 1;i <= 9;i++) { //外层循环,负责9行
            for(int j = 1;j <= i;j++) {//内部循环,负责输出当前
                System.out.print(i+"*"+j+"="+i*j+" ");
            }
            System.out.println();
        }
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/869200.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-13
下一篇 2022-05-13

发表评论

登录后才能评论

评论列表(0条)

保存