#12489: java


zzser15963 (Momentary)

學校 : 國立新營高級中學
編號 : 57840
來源 : [110.30.168.151]
最後登入時間 :
2020-09-26 22:16:48
a040. 阿姆斯壯數 | From: [36.233.7.222] | 發表日期 : 2017-07-29 18:14

package test;

import java.util.Scanner;

public class pratice {

private static Scanner in;

public static void main(String[] args) {
in = new Scanner(System.in);
int number = 0, start = 0, end = 0;
while (in.hasNext()) {
number = 0;
start = in.nextInt();
end = in.nextInt();
for (int i = start; i <= end; i++) {
if (compute(i) == true) {
System.out.print(i + " ");
} else {
number++;
}
}
if (number == end - start + 1) {
System.out.print("none");
}
System.out.println();
}

}

static public boolean compute(int num) {
String temp = null;
temp = String.valueOf(num);
int number = 0;
for (int i = 0; i < temp.length(); i++) {
number += (int) Math.pow((Integer.valueOf(temp.charAt(i)) - '0'), temp.length());
}
if (num == number) {
return true;
} else {
return false;
}

}
}

 
ZeroJudge Forum