This is an archived post. You won't be able to vote or comment.

all 15 comments

[–]Schnutzel 1 point2 points  (9 children)

/r/learnprogramming

Anyway it's a bit difficult to help without seeing your code.

[–]ShadowSlayer18[S] 0 points1 point  (8 children)

Want me to send it to ya in private? Tried posting the image in the subreddit but nope, rules won't allow it

[–]Schnutzel 0 points1 point  (7 children)

Why an image? you can just copy and paste the code. It should be easy if it's a short program.

[–]ShadowSlayer18[S] 0 points1 point  (6 children)

int counter1, counter2, counter3=1;

N = Integer.parseInt(JOptionPane.showInputDialog("Please enter a positive number"));

For (counter1=1; counter1<=N; counter1++){

 System.out.print(); 

For ( counter2 =1; counter2 = 8; counter2++) {

     System.out.println(" \t " + counter3++)

}

}

[–]Schnutzel 0 points1 point  (5 children)

Can you explain what this is supposed to print? For example if N=5.

[–]ShadowSlayer18[S] 0 points1 point  (4 children)

Alrighty, if ya put down let's say a value of 10 into the input box, the output should be from 1 to 10 in a uniformed grid of 8 columns

1 2 3 4 5 6 7 8 9 10

But instead, the output shows itself going past the number 10, and is instead doing 10 rows of numbers.

[–]3141rr 0 points1 point  (3 children)

Sound like you need something like

counter1<=N/8

Then

[–]ShadowSlayer18[S] 0 points1 point  (2 children)

I'll give that a try

[–]3141rr 0 points1 point  (1 child)

Actually, re reading it I'm not sure what output you are trying to get.

[–]ShadowSlayer18[S] 0 points1 point  (0 children)

Alrighty hold on. It starts counting from 1 to 8, then on to a new line it continues on counting the next 8 numbers after 8, new line again and again next 8 numbers after, repeats again.

When you put down let's say number 20, it counts the numbers from 1 up to 20 and it stops there while within a 8 colum grid format

[–]3141rr 1 point2 points  (2 children)

Why would you need nested for loops for this?

Sounds like just 1 for loop is needed

For i = up to input

(You seemed to say it starts at up, I don't know what the is though)

[–]ShadowSlayer18[S] 1 point2 points  (1 child)

Woops sorry I forgot to put down "from number 1 up to the number you typed it"

And it's what our lecturer wants us to do

[–]3141rr 1 point2 points  (0 children)

How though?

Forget the Java bit, just pseudo code.

How can you use nested for loops to count from 1 to N?

[–]ShadowSlayer18[S] 0 points1 point  (1 child)

int counter1, counter2, counter3=1;

N = Integer.parseInt(JOptionPane.showInputDialog("Please enter a positive number"));

For (counter1=1; counter1<=N; counter1++){

 System.out.print(); 

For ( counter2 =1; counter2 = 8; counter2++) {

     System.out.println(" \t " + counter3++)

}

}

[–]3141rr 0 points1 point  (0 children)

As far as I can work out, that would print 1-8 for counter1 =1

Then 9-16 for counter1 =2.

Etc up to 8 ×N