Star Pattern in Java


Q. Write a Java program for Star Pattern (Right-Angled Triangle)

import java.util.Scanner;

public class StarPattern {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // Ask the user for number of rows
        System.out.print("Enter number of rows: ");
        int rows = scanner.nextInt();

        // Generate star pattern
        for (int i = 1; i <= rows; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print("* ");
            }
            System.out.println(); // Move to the next line after each row
        }

        scanner.close();
    }
} 

Q. Write an algorithm for Star Pattern (Right-Angled Triangle)

1. Start
2. Read an integer rows (number of rows)
3. Repeat from i = 1 to rows:
    a. Repeat from j = 1 to i:
        Print "* "
    b. After inner loop, print a new line
4. End 



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.