I am trying to do exactly what the title says. I have no clue how to begin this code other than the knowledge that it will most likely have to have a do-while loop with a body inside the 'while' portion enclosed in braces. I would like to understand this rather than get a straight answer, so if you could either write a code and explain or give more hints at how to do it that would be greatly appreciated! The output needs to look like this:
1 (new line)
1 3 (new line)
1 3 5 (new line)
.. ... (new line)
.. ... ... (new line)
1 ... ... 999997 (new line)
1 ... ... 999997 999999
(It is not letting it show that it increases by 1 odd number each line, so i denoted with "(new line)" I hope it is more readable now.)
OK, thanks to newproducts clarification i was able to write this:
String line = "";
int start = 1;
for(;start <= 999999;)
do{
System.out.println(line);
start += 2;
line += " " + start;
}
while(start <= 999999);
But i face a small problem, 1 does not appear at the start of any of the lines. What am I forgetting to do?
**RESOLVED. I added 1 + line to my print statement and it runs the way I want. Thank you to everyone who tried to help, especially newproduct who new what I needed even with me not wording my question properly.