Win a copy of Kotlin in Action this week in the Kotlin forum!
    Bookmark Topic Watch Topic
  • New Topic

Java Program for Prime numbers  RSS feed

 
Brijesh Shah
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi All,

I have a program here:
/*Program to print prime numbers between 1 to n*/
while(i<=n-1)
{
if((n%i)==0)
{
break;
}
i++;
}
if(i==n)
{
System.out.println("The prime numbers between 1 and " +n+ " are:");
System.out.println(""+n);
}
n--;
}
}

Please help me why this code does not lead me to the end results???
This is a program to find out prime numbers between 1 to N
Thanks in advance....
 
Campbell Ritchie
Marshal
Posts: 55691
163
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't post the same thing twice. Ask one of the bartenders to move your original thread.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
The other thread in JiG(I) has more discussion, so i'm going to close this thread. that is not to say that the other one won't be moved...
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!