4
To solve this exercise:
Write a program that prints a rectangle of n x m asterisks, in the which values of n and m are provided by the user. For example, for values of n = 5 and m = 7, the expected result is:
*******-
*******-
*******-
*******-
*******-
I made this code:
import java.util.Scanner;
public class Rectangloasteriscos { public Static void main(String[] args) { int m, n;
Scanner teclado = new Scanner(System.in);
n = teclado.nextInt();
m = teclado.nextInt();
for (int i=1 ; i <= n ; i++)
{
System.out.println("*");
}
for (int j=1 ; j <= m ; j++)
{
System.out.print("*");
}
It turns out that I did not get the expected result, using the same values of the example, the rectangle of my program comes out like this:
*-
*-
*-
*-
*-
*******-
How to solve this?
The rule is a for to repeat lines and an internal one concatenating each asterisk with the same amount of for
– Marlysson
Is there any restriction on using the standard library?
– Maniero