JAvaは3桁の数字が水仙の数かどうかを判断します
1312 ワード
/**
。
*/
import java.util.Scanner;
public class TestWork {
public static void main(String[] args) {
System.out.println(" ");
Scanner sc = new Scanner(System.in);
if (sc.hasNextInt()) {
int num = sc.nextInt();
if (num > 99 && num < 1000) {
int a = num / 100;//
int b = num / 10 % 10;//
int c = num % 10;//
int result = (int) Math.pow(a, 3) + (int) Math.pow(b, 3) + (int) Math.pow(c, 3);
if (result == num) {
System.out.println(num + " ");
} else {
System.out.println(num + " ");
}
} else {
System.out.println(" ");
}
} else {
System.out.println(" ");
}
}
}
/**
100-999
*/
public class TestWork {
public static void main(String[] args) {
int Narcount=0;//
for (int i = 100; i <= 999; i++) {
int a = i / 100;//
int b = i / 10 % 10;//
int c = i % 10;//
int result = (int) Math.pow(a, 3) + (int) Math.pow(b, 3) + (int) Math.pow(c, 3);
if (result == i) {
Narcount++;
System.out.print(i+"\t");
if(Narcount%5==0){
System.out.println();
}
}
}
}
}