今晚的兴业数据笔试题是不是有问题啊?
编程是输出一个区间的水仙花数,这种题本来很简单的,但是边界情况搞不定,一直是66.7%
package com.yangyang.niuke; import java.util.Scanner; /** * @create: 2020-03-20 23:35 **/ public class Main { private static boolean shui(int num){ int a = num/100; int b = (num/10)%10; int c = num % 10; return a*a*a + b*b*b + c*c*c == num; } private static void check(int n,int m){ if(n <100 || m > 999 || m < n){ System.out.println("ERROR"); return; } int c = 0; for (int i = n; i <= m; ++i) { if(shui(i)){ c++; System.out.println(i); } } if(c == 0) System.out.println("NO DATA"); } public static void main(String[] args){ Scanner sc = new Scanner(System.in); String str = sc.nextLine(); try { String[] ss = str.split(","); int n = Integer.parseInt(ss[0]); int m = Integer.parseInt(ss[1]); check(n,m); } catch (Exception e) { System.out.println("ERROR"); } } }