Try doing it one step at a time to print a box with dimensions width and height,
Going back to post#10:
Write a loop that loops height number of times.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Try doing it one step at a time to print a box with dimensions width and height,
Going back to post#10:
Write a loop that loops height number of times.
If you don't understand my answer, don't ignore it, ask a question.
Ok
--- Update ---
What should I say in if statement for height?
Now put the code for the loop in a main() method and put the main() method in a class. Compile it and execute it.
Fix any errors. Post the full code here.
When that's done, we'll move to the next step.
There isn't an if statement. The for loop controls the number of times the loop will execute.What should I say in if statement for height?
If you don't understand my answer, don't ignore it, ask a question.
Please reread the instructions. You are to write a small class with a main() method and a loop that loops height times.
The program is going to be written one small, simple step at a time.
If you'd rather do the assignment on your own, let me know and I'll leave.
If you don't understand my answer, don't ignore it, ask a question.
All i need is example of loops controls
For testing you should write a simple program as described above to learn the techniques of writing loops and using if statements to control what is printed.
When you have learned how to write the code to do that, you will have an easier time working on your assignment.
Your choice on how to proceed:
Try writing this simple program to learn how to do some programming
or waiting until someone comes along to write the code for you.
If you don't understand my answer, don't ignore it, ask a question.
You can do that? write the code for someone esle?
Ok. Good luck on your project.
If you don't understand my answer, don't ignore it, ask a question.
no I like to learn myself and use your help
Start by writing the code that has been suggested in posts #26, #28 & #30, compile it, fix any errors, execute it, fix any errors and post the working version here.
If you don't understand my answer, don't ignore it, ask a question.
ok
import java.util.Scanner; /* * Stacktrace.in * You have a exception , we have a solution */ public class DrawRectange { public static void main(String[] args) { Rectange rectangle = new Rectange(-1,11); rectangle.draw(); Rectange rectangle2 = new Rectange(4,5); rectangle2.draw(); public class Rectange { private int heigth; private int width; public Rectange(int heigth, int width) { super(); this.heigth = heigth; this.width = width; } public void draw(){ if(heigth<0 || heigth >10){ heigth =3; } if(width<0 || width >10){ width =3; } for(int i=1;i<=heigth;i++) { for(int j=1;j<=width;j++) { if((i==1 || i==heigth) || (j==1 || j==width)) System.out.print("#"); else System.out.print(" "); } System.out.println(); }
--- Update ---
with a error:
----jGRASP exec: javac -g Rectange.java Rectange.java:7: error: class DrawRectange is public, should be declared in a file named DrawRectange.java public class DrawRectange { ^ 1 error ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete.
A class declared as public must be in a file with the filename the same as the classname.DrawRectange is public, should be declared in a file named DrawRectange.java
There can not be two public classes defined in the same file.
Either move the definition of DrawRectangle to a file named: DrawRectange.java
or remove the public modifier from the class definition.
This is an interesting comment in the code:/* * Stacktrace.in * You have a exception , we have a solution */
If you don't understand my answer, don't ignore it, ask a question.
move just public, not public Rectangle?
There can only be ONE class that is public in a .java file and the classname and filename must match,
BTW whoever wrote the code does not know how to spell Rectangle.
If you don't understand my answer, don't ignore it, ask a question.
It makes me wonder just who in fact did write his code.