fork download
  1. import java.util.Scanner;
  2. class Jtutorial1 {
  3. public static void main(String args[]){
  4. Scanner input = new Scanner(System.in);
  5. int i,j;//Declared outside of the loop
  6.  
  7.  
  8. System.out.println("Enter a number: ");
  9. int userSel=input.nextInt();//userSel is how many numbers the following loops will count up to
  10.  
  11. for(i=0; i < userSel; i++){//start outer loop
  12. for(j=1; j<=i; j++){//start inner loop--Inner loop will count until j=i
  13. System.out.print(j);//Print out the current value of j
  14. }//end inner loop
  15. System.out.println();//Go to the next line after printint from 1-(current value of i on each line)
  16. }//end outer loop
  17.  
  18.  
  19.  
  20. for(i=userSel; i >= 0; i--){//start outer loop--count from current value of userself (which = i from last loop down to 0)
  21. for(j=1; j<=i; j++){//start inner loop--Count from 1-current value of i
  22. System.out.print(j);//print current value of j--each time on the same line
  23. }//end inner loop
  24. System.out.println();//Newline once j=i
  25. }//end outer loop
  26.  
  27. //1
  28. //12
  29. //123
  30. //1234
  31. //12345
  32. //1234
  33. //123
  34. //12
  35. //1
  36.  
  37.  
  38. }//end main
  39. }//end class
Success #stdin #stdout 0.07s 213888KB
stdin
9
stdout
Enter a number: 

1
12
123
1234
12345
123456
1234567
12345678
123456789
12345678
1234567
123456
12345
1234
123
12
1