So, I just had a random urge (after reading a previous post) to make an infinite loop that creates this output:
1
12
123
1234
12345
1234
123
12
1
12
123
.... etc.
So far I have this:
import java.util.Scanner; public class ForTriangle { public static void main(String args[]){ Scanner scan = new Scanner(System.in); System.out.println("Enter length of numbers"); int number = scan.nextInt(); int a = 1; int b = 1; while(b < number){ for(a = 1; a <= number; a++){ for(b = 1; b <= a; b++){ if(b == number) a = 0; System.out.print(b); } System.out.println(); } } }//End MM }//End MC
When the user enters 5, it produces:
1
12
123
1234
12345
1
12
123
1234
12345
etc...
Any tips?