返回信息流请问各位大神,为什么我写的求1000以内所有的水仙花数的程序运行之后没有任何输出呢?
谢谢大神们
这是一条镜像帖。来源:北邮人论坛 / java / #40538同步于 2015/5/7
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
为什么我写的求1000以内所有的水仙花数的程序没有输出呢?
singingwheat
2015/5/7镜像同步25 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
你这程序不会抛异常么?
public static void main(String[] args) {
int[] a = new int[10];
int j=0;
for (int i = 100; i <= 999; i++) {
int geWei, shiWei, baiWei;
baiWei = i / 100;
shiWei = (i - baiWei * 100) / 10;
geWei = i - baiWei * 100 - shiWei * 10;
if (i == geWei * geWei * geWei + shiWei * shiWei * shiWei + baiWei
* baiWei * baiWei) {
a[++j]=i;
System.out.println(a[j]);
}
}
}
/*
控制台:
153
370
371
407
*/
不要try{...}catch(Exception e) {...}。本来你的程序会数组越界的,结果这一下什么错都不报了。让main抛出异常吧(main(String[] args) throws Exception)
catch到异常请打印出来。。
【 在 singingwheat 的大作中提到: 】
: 请问各位大神,为什么我写的求1000以内所有的水仙花数的程序运行之后没有任何输出呢?
: 谢谢大神们[upload=1][/upload]