Peoblem 3.03


 Question 3.03:Write a program called SquarePattern that prompts user for the size (a non-negative integer in int); and prints the following square pattern using two nested for-loops.

Enter the size: 5

# # # # #

# # # # #

# # # # #

# # # # #

# # # # #




Solution: 


package com.company;
import java.util.Scanner;
public class Lab03Problem3 {
    public static void main(String[] args)
    {
        Scanner Obj = new Scanner(System.in);
        System.out.print("Enter the size: ");
        int n =Obj.nextInt();
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                System.out.print("# ");
            }
            System.out.println();
        }
    }
}

Previous Post Next Post