a040: 阿姆斯壯數

題目:http://zerojudge.tw/ShowProblem?problemid=a040
程式碼:

import java.util.Scanner;
import java.math.BigInteger;
public class a040 {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Scanner sc = new Scanner(System.in);
  while(sc.hasNext()){
   int a = sc.nextInt();
   int b = sc.nextInt();
   int i,count =0;
   String s="";
   double num = 0;
   for(i=a;i<=b;i++){
     s = String.valueOf(i);
    //System.out.println(s);
     char [] c = s.toCharArray();
     for(int j=0;j<c.length;j++){
      //System.out.print(c[j]+",");
      num += Math.pow(Integer.parseInt(String.valueOf(c[j])), c.length);
     }
     //System.out.println(num);
     if(i==num){
      System.out.print(i +" ");
      count += num;
    }
     
     num = 0;
   }
   if(count==0){
         System.out.print("none");
   }
   System.out.println("");
  }

 }

}

留言

熱門文章