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: Hi everybody i have a little test and i need to ask something

  1. #1
    Member
    Join Date
    Nov 2013
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Hi everybody i have a little test and i need to ask something

    So i have this code ("this is the correct form")
    public static String buildPrimeNumbers(int num){
    		String sum="";int j=num;
    		for (int i=2;i<=(j/2);i++){
    			while (num%i==0) {sum+=i+" ";
    			num=num/i;}
    		}
    	return sum;}
    and i have this one("this is what i did ,its look almost exectly like the first one exept i didnt install int j")
    public static String buildPrimeNumbers(int num){
    		String sum="";
    		for (int i=2;i<=(num/2);i++){
    			while (num%i==0) {sum+=i+" ";
    			num=num/i;}
    		}
    	return sum;}

    my question is my is my code doesn't give me the exact prime numbers as the correct one.
    what is the matter between if i put (i<=(num/2)) or (i<=j/2) .while j==num?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Hi everybody i have a little test and i need to ask something

    The code in the loop changes the value of num. j is unchanged.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Nov 2013
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hi everybody i have a little test and i need to ask something

    Great thanks alot

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Hi everybody i have a little test and i need to ask something

    i have a little test
    Anyone under 4 feet!
    Improving the world one idiot at a time!

Similar Threads

  1. How to test
    By keepStriving in forum Java Networking
    Replies: 2
    Last Post: June 10th, 2013, 10:15 AM