输入
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入您的姓名"); String name = scanner.nextLine(); System.out.println("请输入您的年龄"); int age = scanner.nextInt(); System.out.println("请输入您的工资"); Double aDouble = scanner.nextDouble(); scanner.close();//关闭 System.out.println("----------------------------------"); System.out.println("姓名:"+name); System.out.println("姓名:"+age); System.out.println("姓名:"+aDouble); }
运行结果:
请输入您的姓名 ssss 请输入您的年龄 44 请输入您的工资 4141414.4 ---------------------------------- 姓名:ssss 姓名:44 姓名:4141414.4 Process finished with exit code 0
Demo1
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入年份"); int year = scanner.nextInt(); scanner.close(); if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { System.out.println("闰年"); } else { System.out.println("不是闰年"); } System.out.println("----------------------------------"); Boolean yers = (year % 4 == 0 && year % 100 != 0) || year % 400 == 0; String le=yers ? "闰年":"不是闰年"; System.out.println(le); }
请输入年份 4000 闰年 ---------------------------------- 闰年
Demo2
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入您购买商品的价格是多少"); Double money=scanner.nextDouble(); scanner.close(); if (money>500){ double v = money * 0.09; double ll=money-v; System.out.println("您的实际付款金额是==>"+ll); }else { System.out.println("您的实际付款金额是==>"+money); } }
请输入您购买商品的价格是多少 277 您的实际付款金额是277.0