一,判断客户是否中奖
package com.Bd22HomeWork12_25; import java.util.Scanner; public class Win2 { public static void main(String[] args) { System.out.println("请输入4位会员卡号:"); Scanner sc =new Scanner(System.in);//声明创建Scan对象 int num ;//定义一个四位数数值 num = sc.nextInt();//sc数值赋值给num System.out.println("会员卡号是"+num); int qianwei = num/1000;//求千位数值 System.out.print("千位数:"+qianwei+" "); int baiwei = num/100%10;//求百位数值 System.out.print("百位数:"+baiwei+" "); int shiwei = num/10%10;//求十位数值 System.out.print("十位数:"+shiwei+" "); int gewei = num%10;//求各位数值 System.out.println("个位数:"+gewei); int sum = qianwei+baiwei+shiwei+gewei;//各位数求和 System.out.println("会员卡号"+num+"各位数之和:"+sum);//输出各位数和 String isTrue = sum>20?"会员卡号"+num+"的会员,您中奖了!奖品是MP3!":"会员卡号"+num+"的会员,很遗憾,您没有中奖!";//判断 System.out.println(isTrue);//输出结果 } }
结果如图
二,纸牌互换
package com.Bd22HomeWork12_25; import java.util.Scanner; public class Change { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); System.out.println("输出互换前手中的牌"); System.out.println("左手中的牌:"+a); System.out.println("右手中的牌:"+b); int c = a; a = b; b = c; System.out.println("输出互换后手中的牌"); System.out.println("左手中的牌:"+a); System.out.println("右手中的牌:"+b); } }
结果如图
三.计算银行本金
package com.Bd22HomeWork12_25; import java.util.Scanner; public class Sum { public static void main(String[] args) { System.out.println("请输入本金:"); Scanner sc = new Scanner(System.in); double money = sc.nextInt(); System.out.println("本金为:"+money); double oneYear = money*1.0225; double twoYear = money*1.027; double threeYear = money*1.0324; double fiveYear = money*1.036; System.out.println("存取一年后的本息是:"+oneYear); System.out.println("存取两年后的本息是"+twoYear); System.out.println("存取三年后的本息是"+threeYear); System.out.println("存取五年后的本息是"+fiveYear); } }
结果如图