流程图如下:
文字描述:
1 从键盘上输入整数来判断是否为水仙花数。
2定义一个int类型number,从键盘获取,定义三个变量分别为a, b, c, a代表百分位,b代表十分位,c代表个位。定义一个product(积)的变量等于a * a * a + b * b * b + c* c * c; 然后走判断number是否等于product 为真输出是水仙花数,为假输出不是。
代码展示:
package 课堂练习;
import java.util.Scanner;
public class 练习21 {
public static void main(String[] args){
Scanner myScanner = new Scanner(System.in);
System.out.println("请输入整数:");
int number2 = myScanner.nextInt();
int a = number2 / 100;
int b = (number2 /10) %10;
int c = number2 % 10;
int product = a * a * a + b * b * b + c* c * c;
if(number2 == product){
System.out.println(number2 + "是水仙花数" );
}else {
System.out.println(number2 + "不是水仙花数");
}
}
}