#10939: JAVA AC


william2961 (unknown)

學校 : 不指定學校
編號 : 57434
來源 : [111.248.46.38]
最後登入時間 :
2016-05-20 09:23:22
a040. 阿姆斯壯數 | From: [111.248.46.38] | 發表日期 : 2016-05-19 16:28

import java.util.Scanner;

public class ArmstrongNumber {

public static void main(String[] args) {
// TODO Auto-generated method stub

Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
//String in=sc.nextLine();
//String[] inArray=in.split(" ");
//char[] inCharArray1=inArray[0].toCharArray();
//char[] inCharArray2=inArray[1].toCharArray();
int a=sc.nextInt();
int b=sc.nextInt();
int count=0;
for (int i=a;i<=b;i++){
char [] chars = String.valueOf(i).toCharArray();
int total=0;
for(int j=0;j<chars.length;j++){
total+=Math.pow(Character.getNumericValue(chars[j]),chars.length);
}
if(total==i){
if(count==0){
System.out.print(i);
}
else{
System.out.print(" "+i);
}
count++;
}
}
if(count==0){
System.out.print("none");
}
System.out.println();
}
}

}

 
ZeroJudge Forum