import java.util.Scanner;
public class Test03 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int index; do { index =-1; System.out.println("请输入数字:"); int n =scanner.nextInt(); int sum = 0; while (n > 0) { sum += n % 10; n /= 10; } System.out.println("各位数字之和是"+sum); System.out.println("是否继续?(y/n)"); String s = scanner.next(); if (s.equals("y")){ index=1; }else if (s.equals("n")){ index =2; System.out.println("程序退出"); }else{ index =3; System.out.println("输入有误,请重新输入"); } }while (index!=2);
} }
|