Reputation: 21
I want to draw a Rectangle using asterisks. Actually i have started something but don't know how to continue how to go backwards you can go down by using println but how to go up Any help will be nice
import java.util.Scanner;
public class Shapes
{
public static void main (String [] args)
{
Scanner Read=new Scanner(System.in);
int i;
int j;
int W;
int L;
System.out.println("Enter the Rectangle Width then Lenghts");
W=Read.nextInt();
L=Read.nextInt();
for (i=0;i<W;i++)
{
System.out.println("*");
}
for (j=0;j<L;j++)
{
System.out.print("*");
}
System.out.println("");
}
}
Upvotes: 0
Views: 1454
Reputation: 1029
I will give you an idea.
take a number n, the number of asterisks.
Iteration 1: In the first line print n number of asterisks
iteration 2: print one * in the left and n-2 spaces consecutively and one more * in the right
Only thing is you have to adjust for the newline spacings because the end result might not look like a rectangle despite of having equal number of asterisks.
Upvotes: 4