ShuiXianHua.java 887 字节
Newer Older
W
wumingfang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
import java.util.Scanner;

/**
 * @description:
 * @author: wmf
 * @create: 2022-10-13 14:21
 **/
public class TestMain {
    public static void main(String[] args) {

        Scanner myscanner = new Scanner(System.in);
        System.out.println("请输入数字");  // 提示用户输入
        while(true){
            int number = myscanner.nextInt(); // 接收用户输入

            int number1 = number / 100;  // 取百位
            int number2 = number % 100 / 10; // 取十位
            int number3 = number % 10; // 取个位

            if (number1 * number1 * number1 +
                    number2 * number2 * number2 +
                    number3 * number3 * number3 == number) {
                System.out.println(number + "是水仙花数");
            } else {
                System.out.println(number + "不是水仙花数");
            }
        }

    }
}