Square Learn programming Java

Lesson:

Flow Control


Exercise:

Square


Objetive:

Write a java program that prompts the user to enter a number and a width, and displays a square of that width, using that number for the inner symbol, as shown 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();
		}
	}
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.