To resolve this exercise:
Write a program that prints a rectangle of n x m asterisks in the which values of n and m are supplied 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 RetanguloAsteriscos { 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 as the example, the rectangle of my program goes like this:
* -
* -
* -
* -
* -
******* -
How to solve this?