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

您没有登录

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

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





发贴: 15
积分: 0
于 2005-08-26 22:09 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
我说一下我的要求:
找出100以内的非素数。
我的想法是:以2为开始承以它的倍数,即(2,4,6等)再从3开始,即(6,9等)问题是:为什么6,12 等数会重复出现,我用了
for(int p=0;p<store.length;p++)
  if(store[p]==t)break
语句,是不是这个语句出了问题了!大家帮我看看了!

public class Try{
public static void main(String[] args){
int length=500;
int index=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;
for(int p=0;p<store.length;p++){
  if(store[p]==t)break;
   store[index]=t;    
  }
index=index+1;
}

}
  for(int k=0;k<store.length;k++)
  if(store[k]!=0)
  System.out.print(store[k]+" ");
}
}


why edited on 2005-08-27 05:33


话题树型展开
人气 标题 作者 字数 发贴时间
10826 问题在哪里(没有符合我的要求)(找出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
9239 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