出力が 3 の後に改行されるのはなぜですか? このような:
9
8 7
6 5 4
3
2 1
任意の数値を入力すると、常に 3 の後に新しい行が入力されます。9 を入力すると、ターゲット出力は次のようになります。
9
8 7
6 5 4
3 2 1 0
3 の後に新しい行に入る理由を教えてください。
public class TriangleWithInput {
/**
* @param args
*/
@SuppressWarnings("resource")
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int input = sc.nextInt();
while (input >= 0) {
int c = 1;
while ( c <= input) {
int r = 1;
while (r <= c) {
System.out.print(input + " ");
input--;
r++;
}
System.out.println();
c++;
}
}
}
}