• 求水仙花数字


    一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。

     1 package test02;
     2 
     3 import java.util.ArrayList;
     4 import java.util.Iterator;
     5 import java.util.Scanner;
     6 /*
     7  * 指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。 
     8  * */
     9 public class ShuiXianHua {
    10     public static void main(String[] args) {
    11         Scanner in = new Scanner(System.in);
    12         while(true){
    13             String str = in.nextLine();
    14             String st[] = str.split(" ");
    15             Integer n1 = new Integer(st[0]);
    16             Integer n2 = new Integer(st[1]);
    17             ArrayList<Integer> arr = new ArrayList<Integer>();//用于存储合格数字
    18             for(int i=n1;i<=n2;i++){
    19                 int num1 = i/100;            //得到百位
    20                 int num2 = (i-num1*100)/10;
    21                 int num3 = i-num1*100-num2*10;
    22                 int b0 = (int) java.lang.Math.pow(num1,3);
    23                 int b1 = (int) java.lang.Math.pow(num2,3);
    24                 int b2 = (int) java.lang.Math.pow(num3,3);
    25                 if(i == (b0+b1+b2)){
    26                     arr.add(new Integer(i));
    27                 }
    28             }
    29             if(arr.size() == 0){        //不存在合格的数字
    30                 System.out.print("no");
    31             }else{
    32                 Iterator<Integer> it = arr.iterator();
    33                 for(int i=0;i<arr.size();i++){
    34                     if(i<arr.size()-1){
    35                         System.out.print(it.next() + " ");
    36                     }else{
    37                         System.out.print(it.next());
    38                     }
    39                 }
    40             }
    41             System.out.println();
    42         }
    43     }
    44 }
  • 相关阅读:
    input填入字符会出现黄色
    安装Scrapy时出现问题scrapy unicodedecodeerror ascii codec cant decode byte 0xd1 in position
    SVN 出现:Previous operation has not finished; run 'cleanup' if it was interrupted。
    Myeclipse小技巧
    好的开发网站
    BZOJ 1968
    BZOJ 1010
    BZOJ 1015
    BZOJ 3875
    BZOJ 2705
  • 原文地址:https://www.cnblogs.com/XuGuobao/p/7367920.html
Copyright © 2020-2023  润新知