Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Putting codes in order......

1. ## Putting codes in order......

I have been asked to generate prime numbers between 50 to 60 using snippets being provided. But the snippets are in jumbled order and I am required to put that snippet in order to be able to run this code.....but I find it as herculean task....

further adding to the soln.....the output would be

50 = 1 2 5
51 = 1 3 17
52 = 1 2 13
53 = 1 53
54 = 1 2 3
55 = 1 5 11
56 = 1 2 7
57 = 1 3 19
58 = 1 2 29
59 = 1 59
60 = 1 2 3 5

public class prime
{
public static void main(String[] args)
{
int i = 0 , j , k , p ;

j = 1 ;

p = 0 ;

for(i = 51 ; i < 62 ; i ++) {

k = 2 ;

while(k <= (j-1)) {

if(j % k == 0)

p ++ ;

else {

j ++ ;

k ++ ; }

if(j == 1 || j == 2 || j == 3)

} while( j <= i ) ; }

if((i - j) % j == 0 ) {

System.out.println(j) ;

do {

if(p == 0)

System.out.println(j) ; }}

System.out.println(i-1) ;