java第三次作业

1.输入商品单价,数量,求总价。活动8折后抹零,计算活动价。
输入付款金额,计算找零并输出

package School.Day3;

public class Test1 {
    public static void main(String[] args) {
        java.util.Scanner s = new java.util.Scanner(System.in);
        System.out.print("商品单价: ");
        double danjia = s.nextDouble();
        System.out.print("商品数量: ");
        int shuliang = s.nextInt();
        double zongjia = danjia * shuliang;
        System.out.println("商品总价: " + zongjia);
        int zongjia2 = (int)(zongjia * 0.8);
        System.out.println("折后价: " + zongjia2);
        System.out.print("付款金额: ");
        int fukuan = s.nextInt();
        System.out.println("找零: " + (fukuan - zongjia2));
    }
}

  

2.输入一个三位数,求个位,十位和百位。

package School.Day3;

public class Test2 {
    public static void main(String[] args) {
        java.util.Scanner s = new java.util.Scanner(System.in);
        System.out.print("输入三位数: ");
        int x = s.nextInt();
        if (x<100 || x>999) {
            System.out.println("数字错误!");
            return;
        } else {
            System.out.println("百位数: " + x/100);
            System.out.println("十位数: " + x%100/10);
            System.out.println("个位数: " + x%10);
        }
    }
}

  

3.输入大写字母,转成对应的小写字母

package School.Day3;

public class Test3 {
    public static void main(String[] args) {
        java.util.Scanner s = new java.util.Scanner(System.in);
        System.out.print("输入大写字母: ");
        String x = s.next();
        String x2 = x.toLowerCase();
        System.out.println(x + "的小写是" + x2);
    }
}

  

4.输入2个数,用三目运算符,输出较大数

package School.Day3;

public class Test4 {
    public static void main(String[] args) {
        java.util.Scanner s = new java.util.Scanner(System.in);
        System.out.print("输入第一个数: ");
        double a = s.nextDouble();
        System.out.print("输入第二个数: ");
        double b = s.nextDouble();
        double c;
        boolean i = a > b;
        c = i ? a : b ;
        System.out.println(c);
    }
}

  

posted @ 2021-03-27 11:51  李芊  阅读(65)  评论(0编辑  收藏  举报