1 package com.work0624; 2 /** 3 * 练习题 4 * 求4位会员卡号之和 5 * @author L 6 */ 7 import java.util.Scanner; 8 9 public class Work3 { 10 static Scanner sc = new Scanner(System.in); 11 public static void main(String[] args) { 12 System.out.println("请输入4位会员卡号"); 13 int card = sc.nextInt(); 14 int qian = card /1000;//求4位会员卡号的千位数 15 int bai = card % 1000 /100;//求4位会员卡号的百位数 16 int shi = card /10 % 10;//求4位会员卡号的十位数 17 int ge = card % 10;//求4位会员卡号的个位数 18 System.out.println("会员卡号是:" + card); 19 System.out.println("千位数是:" + qian +",百位数是:" + bai + ",十位数是:" + shi + ",个位数是:" + ge ); 20 System.out.println("会员卡号" + card + "各位之和:" + (qian + bai + shi + ge) ); 21 } 22 }