import java.util.*; public class Bank{ public static void main(String []agrs){ //给用户开一个键盘录入的入口 Scanner input = new Scanner (System.in); System.out.print("请输入四位会员卡号:"); //用变量来接收录入的数值 String用input.next() double用input.nextDouble() int num = input.nextInt(); //使用除法和取余的方式将卡号各数独立分开 int geWei = num%10; int shiWei = num/10%10; int baiWei = num/100%10; int qianWei =num/1000; System.out.println("会员卡号的个位是:"+geWei+"十位是:"+shiWei+"百位是:"+baiWei+"千位是:"+qianWei); //算出各数之和 int sum = geWei+shiWei+baiWei+qianWei; System.out.println("各数之和是:"+sum); //使用条件运算符来判断是是否中奖,判断的条件是总和是否为偶数。 String winning = (sum%2==0)?"恭喜你,中奖啦!!!":"谢谢参与!"; System.out.println(winning); } }
时间: 2024-11-07 00:50:23