HDU—OJ 、2010

import java.util.Scanner;
//注意类名
public class Narcissistic_Number {
    @SuppressWarnings("null")
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int m = scanner.nextInt();
            int n = scanner.nextInt();

            boolean bool = true;
            StringBuffer sb = new StringBuffer(" ");

            for (int i = m; i <= n; i++) {

                int unit = i % 10;

                int decade = (i / 10) % 10;
                int hundred = (i / 100);
                int sum = (int) (Math.pow(unit, 3) + Math.pow(decade, 3) + Math.pow(hundred, 3));
                if (i == sum) {
                    String s = Integer.toString(i);
                    sb.append(s);
                    sb.append(" ");
                    bool = false;
                }
            }
            if (bool) {
                System.out.println("no");
            } else {
                String str = sb.substring(1, sb.length() - 1);
                System.out.println(str);
            }
        }
    }
}

注意:输出格式,输出的数据都应该在一行上(本题),且最后不能是空格,这次本小白就犯了这样一个低级错误得到一个PE,哭唧唧。并且找哪里错误调试很了小半个小时,心累。

Presentation Error (PE) : 虽然您的程序貌似输出了正确的结果,但是这个结果的格式有点问题。请检查程序的输出是否多了或者少了空格(’ ‘)、制表符(’\t’)或者换行符(’\n’)

猜你喜欢

转载自blog.csdn.net/qq_39745932/article/details/82624341