JAVA系统学习

package cn.itcast.day01;

public class HelloWorld {
    static String s1 = "hello";
    public static void main(String[] args){
        String s2 = "world";
        System.out.println(s1);
        System.out.println(s2);
    }
}

数据类型:

package cn.itcast.day01;

public class Demo0Method{
    static final double PI = 3.14;
    static  int age = 25;
    public static void main(String[] args){
        one();
        two();
        three();
        four();
        five();
    }
    public static void one(){
        for(int i = 0;i < 5; i++){
            for (int j = 0; j < 4; j++) {
            System.out.println('*');
            }
            }
        }
    public static void two(){
        byte a = 64;
        short b = 32564;
        int c = 23;
        long d = 235682441;
        long e = a + b + c + d;
        float f = 15.26f;
        double g = 14452.12d;
        double h = f + g;
        System.out.println(h);
        System.out.println("结果是:" + e);
    }
    public static void three(){
        final int number;
        char word = 'j',word2 = 'k';
        int p = 12456,g = 2545;
        char c1 = '\\';
        char c2 = '\u4545';
        number = 154578;
        System.out.println("Word对应的位置是:" + (int)word);
        System.out.println("word2对应的位置是:" + (int)word2);
        System.out.println("p和g对应的Unicode是:" + (char)p + (char)g);
        System.out.println(c1);
        System.out.println(c2);
        System.out.println(number);
        System.out.println(PI);
    }
    public static void four(){
        int a = 12;
        int b = 25;
        int c = a + b;
        System.out.println(c);
        System.out.println("和为:" + (a + b));
        System.out.println("商为:" + (a / b));
        System.out.println(a > b);
        System.out.println(a != b);
        boolean res = (a < b)&&(a != b);
        boolean res1 = (a < b )||(a == b);
        System.out.println(res);
        System.out.println(res1);
        boolean d = 20 < 12? true:false;
        System.out.println(d);
    }
    public static void five(){
        byte mybyte = 127;
        int myint = 12;
        float myfloat = 12.45f;
        double mydouble = 153.254;
        char mychar = 12;
        System.out.println("byte和float的运算结果:" +(mybyte + myfloat));
    }
}

循环结构:

package threeday;
import java.util.Scanner;

public class circulation {
    public static void main(String[] args){
    // one();
    // two();
       // three();
    //    four();
       // five();
      //  six();
      //  seven();
       // eight();
       // nine();
     //   ten();
       // eleven();
        twelve();
    }
    public static void one(){
        int x = 20;
        int y = 30;
        System.out.println(y);
        String word = "hello java";
        if(x > y){
            System.out.println(word);
        }
        else{
            System.out.println("NO Print");
        }
    }

    public static void two(){
        Scanner s = new Scanner(System.in);
        System.out.println("输入的年份是:");
        int year = s.nextInt();

        boolean flag = ((year % 4 ==0) && (year % 100 !=0)) || (year % 400 == 0);
        String isyear = flag ? "是闰年":"不是闰年";
        System.out.println(isyear);
    }

//    超市柜台收银程序
    public static void three(){
        Scanner scan = new Scanner(System.in);
        System.out.println("商品种类:");
        int keed = scan.nextInt();
        double count_money = 0;

        for(int i = 0;i < keed; i ++){
            System.out.println("商品的单价:");
            float price = scan.nextFloat();
            System.out.println("商品数量:");
            int num = scan.nextInt();
            double count_number = 0;
            count_number = price * num;
            count_money += count_number;
        }
        if(count_money > 800){
            count_money = count_money * 0.7;
            System.out.println("应付:" + count_money);
        }
        else if (count_money > 500 && count_money <= 800){
            count_money *= 0.85;
            System.out.println("应付:" + count_money);
        }
        else{
            System.out.println(count_money);
        }
    }

    public static void four(){
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入1-7整数:");
        int num = scan.nextInt();
        switch (num){
            case 1:
                System.out.println("星期一");
                break;
            case 2:
                System.out.println("星期二");
                break;
            case 3:
                System.out.println("星期三");
                break;
            case 4:
                System.out.println("星期四");
                break;
            case 5:
                System.out.println("星期五");
                break;
            default:
                System.out.println("休息日");
        }
    }

    public static void five(){
        int num = (int)(Math.random() * 1000 + 1);
        System.out.println(num);
        Scanner scan = new Scanner(System.in);
        System.out.println("猜吧");
        int guess = scan.nextInt();
        while (guess != num){
            if (guess > num){
                System.out.println("太大了");
            }
            if(guess < num){
                System.out.println("小了");
            }
            if(guess == 0){
                System.out.println("结束");
            }
            guess = scan.nextInt();
        }
        System.out.println("猜对了");
    }

    public static void six(){
        int x = 1;
        int sum = 0;
        while (x <= 10){
            sum = sum + x;
            x++;
        }
        System.out.println(sum);
    }
    public static void seven(){
        int num = (int)(Math.random() * 1000 +1);
        Scanner scan = new Scanner(System.in);
        int guess;
        do{
            System.out.println("猜吧:");
            guess = scan.nextInt();
            if(guess > num){
                System.out.println("大了");
            }
            if(guess < num){
                System.out.println("小了");
            }
            if(guess == 0){
                System.out.println("不猜了");
                break;
            }
        }while (guess != num);
        if(guess == num) {
            System.out.println("猜对了");
        }
    }

    //个人所得税
    public static void eight(){
        double salary = 130000.0;
        double taxsalary = salary - 5000;
        if(taxsalary <= 0.0){
            System.out.println("应缴税0.0");
        }
        if(taxsalary > 0 && taxsalary < 10000.0){
            double tax = taxsalary * 0.03;
            System.out.println("应缴税:" + tax);
        }
        if(taxsalary >= 10000.0){
            double tax = taxsalary * 0.25;
            System.out.println("应缴税:" + tax);
        }
    }

    public static void nine(){
        loop: for(int i = 0;i < 10; i++){
            for(int j = 0; j <10 ; j++){
                if(j == 4){
                    break loop;
                }
                System.out.println("i=" + i +"j=" + j);
            }
        }
    }
    public static void ten(){
        int i=0;
        for(;i < 10; i++){
            if(i % 3 == 0){
                continue;
            }
            System.out.println(i);
        }
    }

    public static void eleven(){
        Scanner scan = new Scanner(System.in);
        for (int i = 0; i < 4; i++){
            //出题
            int num1 = (int)(Math.random()*100);
            int num2 = (int)(Math.random()*100);
            int num_score = num1 + num2;
            System.out.println(num1 + "+" + num2 + "=");
            //计算
            int score = scan.nextInt();
            while (score != num_score){
                score = scan.nextInt();
            }
        }
    }

    public static void twelve(){
        for(int i = 1;i <= 9; i++){
            for(int j = 1; j <= i; j++){
                int num = i * j;
                System.out.print(i + "*" + j + "=" + num + "\t");
            }
            System.out.println();
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值