Results 1 to 4 of 4
Thread: Help with Java Question
- 03-29-2011, 09:26 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 16
- Rep Power
- 0
Help with Java Question
This is the question..
Write a method which takes 2 integer parameters, and prints out a rectangle of *’s,
where:
• The 1st parameter is the width of the rectangle
• The 2nd parameter is the height of the rectangle
• Only the border (outer layer) of the rectangle is printed
For example, if the method was given the values 8 and 5 (in this exact order)
also the method should print nothing if the value of any parameters it is given is less than 2.
Here is my code so far...
class
{
public static void main(String[] args)
{
int a=8;
int b=5;
System.out.println("*");
isArea();
}
public static int isArea()
{
int i=8;
return i;
}
- 03-29-2011, 09:30 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Your code is way off what you want, your main method should only contain a line which calls the static method.
The static method doesn't need a return type so make it void(all it does is print everything)
I'm guessing this is an exercise on loops so think of using them. First draw a solid rectangle and see if you can figure it out. Once you get it to draw a solid rectangle it shouldn't be too difficult for the outline.
- 03-29-2011, 09:49 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 16
- Rep Power
- 0
Hey sundee, i have got this so far but i am stuck..
class
{
public static void main(String[] args)
{
int a=8;
int b=5;
System.out.println();
isArea();
}
public static int isArea()
{
int width=5;
for (int i=0; i<width; i++)
System.out.print("*");
return 5;
}
}
- 03-29-2011, 10:09 AM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
There is still a lot wrong with this but your are getting close. First, this method is supposed to take two arguments. I am also not sure it should return an int. Did you try compiling it and running it? The best way to learn is to compile and run the code. Play with it, get used to common compiler errors and learn to fix them. Learn to understand exception stack traces. I also suggest you read some of the sun tutorials.
Similar Threads
-
java question
By joe98 in forum New To JavaReplies: 7Last Post: 03-23-2011, 07:09 AM -
sorry for this question - which is best ? .NET c# or java ?
By funkygarzon in forum Forum LobbyReplies: 33Last Post: 01-21-2011, 03:07 PM -
Need help with java question
By ccie007 in forum New To JavaReplies: 23Last Post: 05-18-2010, 06:32 PM -
Java Question :D
By thisisIT in forum New To JavaReplies: 6Last Post: 03-12-2010, 04:04 PM -
Java Question
By Jay-1.1 in forum New To JavaReplies: 11Last Post: 05-01-2008, 04:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks