galinyotsev123

ProgBasics07Nested-Loops-Y02numberPyramid

Jan 9th, 2019
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class Y02numberPyramid {
  5. public static void main(String[] args) {
  6. Scanner sc = new Scanner(System.in);
  7.  
  8. int n = Integer.parseInt(sc.nextLine());
  9. int count = 1;
  10. int i = 1;
  11. boolean breakChecker = false;
  12.  
  13. while (i <= n) {
  14.  
  15. int j = 1;
  16. if (breakChecker) break;
  17.  
  18. while (j <= i) {
  19.  
  20. System.out.print(count);
  21.  
  22. if (count==n) {
  23. breakChecker = true;
  24. break;
  25. } else {
  26. count++; //j++ is down, cause j++ will f**k next if statement.
  27. } //count++ is here, because we don't want spaces at the end of every row. (even if its short)
  28.  
  29. if (j==i) { //because we don't want spaces in the end of the row
  30. System.out.println();
  31. } else {
  32. System.out.print(" ");
  33. }
  34.  
  35. j++; //it has to be here downstairs, especially it has a dog in any fight upstairs...
  36. }
  37.  
  38. i++;
  39. }
  40. }
  41. }
Add Comment
Please, Sign In to add comment