Some basic for loops I'm stuck on.
Sequences for n = 5:
I have to make it so it prints that, each on a new line, exactly like that.
Re: Some basic for loops I'm stuck on.
What do you expect us to do, write the code for you?
How about working out what the sequence for each output is. Some are easier than others. Once you know the sequence, the Java code will follow.
Re: Some basic for loops I'm stuck on.
Quote:
Originally Posted by
Junky
What do you expect us to do, write the code for you?
How about working out what the sequence for each output is. Some are easier than others. Once you know the sequence, the Java code will follow.
I'm aware of the sequence for some, not all.
I'd post the code I have if I was at school at the moment.
Re: Some basic for loops I'm stuck on.
Each loop will require 2 or more variables. You might also need to ise an if statement inside some of the loops. None are very difficult.
Re: Some basic for loops I'm stuck on.
Quote:
Originally Posted by
Junky
Each loop will require 2 or more variables. You might also need to ise an if statement inside some of the loops. None are very difficult.
That really doesn't help me. I realize what I'm supposed to do, but I can't figure out how to do it.
Re: Some basic for loops I'm stuck on.
But if I told you how to do it I would have done the work not you. On the other hand if you make an attempt, get stuck and ask a specific question about your code I can provide hints and guide you towards doing the work yourself.
Re: Some basic for loops I'm stuck on.
Quote:
Originally Posted by
Junky
But if I told you how to do it I would have done the work not you. On the other hand if you make an attempt, get stuck and ask a specific question about your code I can provide hints and guide you towards doing the work yourself.
I'd post my code, but unfortunately I'm at school and can't access the necessary files for BlueJ on the school server. Thanks anyways.
Re: Some basic for loops I'm stuck on.
Code :
a = 1;
int b = 1;
for (int i = 1; i <= n; i++) //come back to this later
{
System.out.print(a + " ");
}
There's my code. (For the first set of outputs)
Re: Some basic for loops I'm stuck on.
Does it compile?
Does it run?
Does it do what you want?