Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.


+18 votes




public static void printNumbers(){
      for (int line = 1; line <= 8; line++){
          for (int star = 1; star <= (9 – line); star++){

Does anyone know why in the output the solution says to use " System.out.println(line)" ?

asked in CSC211_Winter2018 by (3.1k points)
edited by

I am not sure why this looks so strange when I post it but it is for the chapter 1 test review question 8.

I want to know why the answer suggest that you use System.out.println(line).....

I do not get how this would print out the desired number at the end of each line.

I would think you would want to use star instead of line here.


I fixed the formatting of your post.

You probably want to mark those sections as "CODE" using the { } button when using the Q&A editor. Otherwise things like ** have special meaning (like bold or italics), because the Q&A website uses the "Markdown" markup language for formatting...

2 Answers

+8 votes

I think there's a problem with what you have written here, because the input you gave will not print what you have in the output. As is, your code will print the following to console:


This has to do with the variable line counting up from 1 when it should be counting down from 8, or perhaps a mathematical operation not being applied to the System.out.println(line); statement you have. Try switching things around so one matches the other and vice versa.

answered by (6.5k points)
–4 votes

It could be done without using a nested for loop!

answered by (3.5k points)