Java Online Compiler
Example: Solid Rectangle Star Pattern in Java
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Solid Rectangle Star Pattern import java.util.Scanner; // Main class containing the entry point of the program public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Step 1: Prompt user for the number of rows System.out.print("Enter the number of rows for the solid rectangle: "); int rows = scanner.nextInt(); // Step 2: Prompt user for the number of columns System.out.print("Enter the number of columns for the solid rectangle: "); int cols = scanner.nextInt(); System.out.println("\nSolid Rectangle Pattern:"); // Step 3: Outer loop iterates through each row for (int i = 0; i < rows; i++) { // Step 4: Inner loop iterates through each column in the current row for (int j = 0; j < cols; j++) { // Step 5: Print an asterisk for every position System.out.print("*"); } // Step 6: After printing all columns for a row, move to the next line System.out.println(); } scanner.close(); } }
Output
Clear
ADVERTISEMENTS