Square Learn programming Java

Lesson:

Flow Control


Exercise:

Square 54


Objetive:

Write a java program which asks for a number and a width, and displays a square of that width, using that number for the inner symbol, as in this example:

Enter a number: 4
Enter the desired width: 3

444
444
444


Code:

import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
		int n; // User entered data
		int row, column; // For loops

		System.out.print("Enter a number: ");
		n = Integer.parseInt(new Scanner(System.in).nextLine());

		System.out.print("Enter the desired: ");
		width = Integer.parseInt(new Scanner(System.in).nextLine());

		for (row = 0; row; row++)
		{
			for (column = 0; column; column++)
			{
				System.out.print(n);
			}

			System.out.println();
		}
	}
}