This repository contains a set of simple Java programs that demonstrate how to print various patterns using loops and basic logic. The code is grouped into three categories: character patterns, number patterns, and star patterns.
-
Character Patterns/
- Programs that print patterns using letters (A, B, C, ...).
- Example:
pattern1.javaprints a triangle of increasing alphabets.
-
Number Patterns/
- Programs using digits (1, 2, 3, ...).
- Each file corresponds to a different pattern (triangles, pyramids, matrices, etc.).
-
Star Patterns/
- Patterns made with the asterisk (
*) character. - Common exercises include pyramids, diamond shapes, and right/left aligned triangles.
- Patterns made with the asterisk (
Each folder contains 12 example programs named pattern1.java through pattern12.java.
- Open any pattern file in your favorite Java IDE or a text editor.
- Compile using
javac:javac pattern1.java
- Run the compiled class and provide an integer input (rows/size) when prompted:
java pattern1
- Observe the printed pattern in the console.
All programs read a single integer from standard input which controls the size of the pattern.
- Copy one of the existing files and update the logic to create a new pattern.
- Maintain the same input strategy (read an integer from
Scanner). - Use descriptive comments at the top to indicate what the pattern looks like.
These examples are ideal for beginners learning how to use:
forloops (nested loops)Scannerfor input- Basic control flow and character/number arithmetic
- Console output formatting with
System.out.printandprintln
Feel free to explore, modify, and extend these programs as you learn Java!
Created on Feb 20, 2026