chaibs

loops-hw6

Dec 27th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class hw6 {
  4.  
  5.     public static void main(String[] args) {
  6.         int num = 0;
  7.  
  8.         Scanner s = new Scanner(System.in);
  9.  
  10.         System.out.println("Please enter a number");
  11.         num = s.nextInt();// getting number from user
  12.  
  13.         for (int i = num, k = 1; i > 0; i -= 1, num -= 1, k += 1) {// loop for the rows
  14.             for (int j = 0; j < num; j += 1) {// loop for the columns
  15.                 System.out.print("*");// prints *
  16.             }
  17.             System.out.println();// next line
  18.             for (int j = 0; j < k; j++) {// loop for spaces
  19.                 System.out.print(" ");// prints spaces
  20.             }
  21.         }
  22.     }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment