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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

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

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

    please help me.....

    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) ;
    Last edited by rdmighty; March 1st, 2012 at 09:33 AM.


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Putting codes in order......

    Help you in what? What's your question?

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Putting codes in order......

    I have to rearrange those syntax in the program in correct order to generate answer as mentioned.....

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Putting codes in order......

    What's the original order and syntax? What have you tried so far? What problems are you facing? If there are errors/exceptions, paste here. If it's giving different results, provide here with the test cases you've applied.

Similar Threads

  1. Help in putting actions to buttons
    By juliusmasa in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 14th, 2011, 06:22 AM
  2. PUTTING JSCROLLPANE INSIDE JFRAME
    By fueledbyjace in forum AWT / Java Swing
    Replies: 0
    Last Post: September 15th, 2011, 07:21 AM
  3. Need help putting GUI in program!
    By greyfox175 in forum AWT / Java Swing
    Replies: 5
    Last Post: May 4th, 2011, 08:55 PM
  4. Reading a file, then putting it in an array
    By Gondee in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 16th, 2010, 11:11 AM
  5. Putting text fields in an array
    By Movies32 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 10th, 2010, 06:46 PM