|
-
Rectangle program
Hi i need to write a program that asks the user for the length and width of a rectangle, and must print the rectangle using *'s .... for example a width of 5 and length of 7
* * * * * * *
* *
* *
* *
* *
* *
* * * * * * * ...
i have the program all set,,, but the right side does not print properly, unless i put 5x7 for the width and length... other values print incorrect......
here is my code:
/*
import java.io.*;
public class Class1
{
public static void main(String[] args) throws IOException
{
BufferedReader IN= new BufferedReader(new InputStreamReader(System.in));
System.out.print(" what is the width >");
int width=Integer.parseInt(IN.readLine());
System.out.print(" what is the length >");
int length=Integer.parseInt(IN.readLine());
if(width<=0)
{
System.out.print(" Invalid amount!");
}
else if(length<=0)
{
System.out.print(" Invalid amount!");
}
System.out.println();
System.out.println();
//top length of rectangle
int count=0;
while(length>count)
{
System.out.print(" * ");
count+=1;
}
//left side
count=1;
int next=0;
System.out.println();
int length2=(length*2)+2;
while(width>count)
{
System.out.print(" *");
//right=length*2)
while(length2>next)
{
System.out.print(" ");
next+=1;
}
System.out.print(" *");
System.out.println();
count+=1;
next=0;
}
// bottom
count=0;
while(length>count)
{
System.out.print(" * ");
count+=1;
}
System.in.read();
}
}
*/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks