杭电2010 ( 水仙花数 ) java

来源:互联网 发布:app软件开发哪家好 编辑:程序博客网 时间:2024/05/24 01:38
import java.util.Scanner;public class Main {    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int i, j, n, m, a, b, c;        while (sc.hasNextInt()) {            m = sc.nextInt();            n = sc.nextInt();            for (i = m, j = 0; i <= n; i++) {                a = i / 100;                b = i / 10 % 10;                c = i % 10;                if (a * a * a + b * b * b + c * c * c == i) {                    if (j > 0) {                        System.out.print(" " + i);                    } else {                        System.out.print(i);                    }                    j++;                }            }            if (j == 0) {                System.out.print("no");            }            System.out.println();        }    }}

0 0
原创粉丝点击