Rectangle V2 Learn programming Java



Lesson:

Flow Control


Exercise:

Rectangle V2


Objetive:

Write a java program that asks for a number, width, and height, and displays a rectangle of that width and height, using that number for the inner symbol, as shown in the example below:

Enter a number: 4
Enter the desired width: 3
Enter the desired height: 5

444
444
444
444
444


Code:

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

		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());

		System.out.print("Enter the desired height: ");
		height = 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.