Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need Help with Nested Loop

843789Feb 28 2010 — edited Feb 28 2010
Hello All , whats up ? , i thought life is easy but it seems that it is getting difficult with programming , i am giving it a shot to use that thing which inside my skull (Brain).... well , i am attempting to Write a program that displays all the numbers from 100 to 200, ten per line, that are divisible by 5 or 6, but not both. well i know i will have to use loops but hold on a little , i am pretty sure that i will have to use Nested loop , i understood that outer loop controls of how many rows and inner loop controls of the width of the row , here is the code i written so far :

public class PerLine {

    public static void main(String[] args) {

       



        for (int numbers = 100; numbers < 200; numbers++) {

            if (numbers % 5 == 0 || numbers % 6 == 0) {
                System.out.print(numbers + " ");
            }

        }

    }
}
however i tried to put outer loop to control width but i could not reach the righ answer , all i got that output repeats itself for a particular rows :(( , so please tell me do i have to study Simple Sorting and Advanced in Data Structures, if you are gonna help me, i will be just happy .

Angel
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 28 2010
Added on Feb 28 2010
4 comments
347 views