Write a java programs to print the following patterns Square pattern
- User
Write a java programs to print the following patterns
Square pattern
- Assistant
Sure! Below is a simple Java program to print a square pattern. This example assumes that the square will have a size of 5 (i.e., 5 rows and 5 columns), but you can modify the size by adjusting the
nvariable.Square Pattern
Here is the Java program to print a square pattern:
javapublic class SquarePattern { public static void main(String[] args) { int n = 5; // size of the square // Nested loop to print the square pattern for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { System.out.print("* "); } System.out.println(); } } }Explanation:
- User
Write a java programs to print the following Triangle pattern Sample Input 5
Sample Output * **
in while loop
- Assistant
Certainly! Below is a Java program that prints a right-angled triangle pattern using a while loop. The size of the triangle is determined by the input value
n.Triangle Pattern using While Loop
Here's the Java code:
java