Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 实战错误讨论  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:问题在哪里(没有符合我的要求)(找出100以内的非素数) [Re:fossil]
fossil





发贴: 15
积分: 0
于 2005-08-28 09:28 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
根据楼上的问题我作了说明程序:
public class Win{
public static void main(String[] args){
int length=500;
int index=0;
int q=0;
int[] store=new int [length];
for(int i=2;i<=100;i++){
for(int j=2;j<=100/i;j++){
int t=i*j;
store[q]=t;
System.out.print("Q: "+store[q]+" ");
System.out.print(q+" ");
for(int p=0;p<store.length;p++){
if(store[p]==t){
  store[q]=0;
  System.out.print("P: "+p);
  store[p]=t;
  }
}
q++;}
}
for(int k=0;k<store.length;k++)
if(store[k]!=0)
System.out.print(store[k]+" ");
}
}

拿出一组数据可以说明:
第一组:
第一次:Q=6 q=1 P=1
第二次:Q=6 q=46 P=1

第二组:
第一次:Q=12 q=4 P=4
第二次:Q=12 q=51 P=4

可以看出p的值是一样的,所以不难理解 store[p]=t这个运算就是在附值运算。
如果没有这一句。整个for循环就没有意义了,也就是说一直在store[q]=0;这个运算。所以最后是什么也不输出了!第二个问题也是这样的!




话题树型展开
人气 标题 作者 字数 发贴时间
10825 问题在哪里(没有符合我的要求)(找出100以内的非素数) fossil 720 2005-08-26 22:09
9770 Re:问题在哪里(没有符合我的要求) xzhslr 794 2005-08-27 01:50
9248 Re:问题在哪里(没有符合我的要求)(找出100以内的非素数) fossil 23 2005-08-28 15:22
9393 Re:问题在哪里(没有符合我的要求)(找出100以内的非素数) eva841205 14 2005-10-12 16:14
9446 Re:问题在哪里(没有符合我的要求)(找出100以内的非素数) mapletree 15 2005-10-24 00:55
9346 Re:问题在哪里(没有符合我的要求)(找出100以内的非素数) fossil 14 2005-08-27 09:56
9101 Re:问题在哪里(没有符合我的要求)(找出100以内的非素数) truthawp 93 2005-08-27 12:58
9202 Re:问题在哪里(没有符合我的要求)(找出100以内的非素数) fossil 34 2005-08-27 13:39
9317 Re:问题在哪里(没有符合我的要求)(找出100以内的非素数) truthawp 725 2005-08-27 19:26
9293 Re:问题在哪里(没有符合我的要求)(找出100以内的非素数) fossil 809 2005-08-28 09:28
9141 Re:问题在哪里(没有符合我的要求)(找出100以内的非素数) truthawp 53 2005-08-28 11:45
9238 Re:问题在哪里(没有符合我的要求)(找出100以内的非素数) fossil 54 2005-08-28 12:08
9116 Re:问题在哪里(没有符合我的要求)(找出100以内的非素数) truthawp 114 2005-08-28 12:39

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923