: Write a program which inputs a positive integer n and outputs an n line high triangle of '*' characters whose right-angle is in the bottom left corner
SOLUTION CODE FOR THE QUESTION
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// write your code here
Scanner sc = new Scanner(System.in);
System.out.print("Enter a positive number: ");
int positive_number = sc.nextInt();
for(int i=0; i<positive_number; i++){
for(int j=0; j<=i; j++){
//print the character and a space for good formatting
System.out.print("* ");
}
//Go in newline
System.out.println(" ");
}
}
Comments
Leave a comment