手记

将数字的每一位分离(Dome)

import java.util.Scanner;
public class reward {
public static void main(String[] args) {
    int cardnumber; 
    System.out.println("请输入会员卡卡号末四位数字:");
    Scanner input = new Scanner(System.in);
    cardnumber= input.nextInt();
    int gewei = cardnumber% 10; 
    int shiwei = cardnumber/ 10 % 10; 
    int baiwei = cardnumber/ 100 % 10; 
    int qianwei = cardnumber/ 1000;
    int sum = gewei + shiwei + baiwei + qianwei;
    System.out.println("会员卡号末位四位数字" + cardnumber + "各位之和: " + sum);
    boolean isLuck=sum>20;
    System.out.println("该用户是幸运客户吗?" +isLuck);
    }
}
1人推荐
随时随地看视频
慕课网APP