Easy Right Sided Java Triangle 2
- Categories Java
Write a java pattern programs triangle to print pattern as shown where no of rows are given by user.
Enter the number of rows: 5
* * * * *
* * * *
* * *
* *
*
import java.util.Scanner; public class RightStarTriangle { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter the number of rows:"); int n= sc.nextInt(); for (int i = 1; i<=n ; i++) {
for (int j = 1; j<=i; j++) {
System.out.print(“ ”);
}
for (int j = i; j<=n; j++) {
System.out.print(“* ”);
}
System.out.println();
} } }
You may also like
Single Linked List Programs in Java
28 August, 2021
Implementing Stack using Array in Java
28 August, 2021
Constructor Programs
3 July, 2021