Sample Run1
Enter a positive integer: 5
Output1:
*
**
***
****
*****
Sample Run2
Enter a positive integer: -36
Output1: The number entered is not positive
Sample Run3
Enter a positive integer: 10
Output1:
*
**
***
****
*****
******
*******
********
*********
**********
import java.util.Scanner;
public class App {
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in);
System.out.print("Enter a positive integer: ");
int n = keyBoard.nextInt();
if (n < 0) {
System.out.println("The number entered is not positive");
} else {
for (int i = 1; i <= n; i++) {
for (int j = 0; j <i; j++) {
System.out.print("*");
}
System.out.println();
}
}
keyBoard.close();
}
}
Comments
Leave a comment