Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

What do I need to add in a Main class?

807607Jan 14 2007 — edited Jan 16 2007
I just realized that I need to add a main class in my work, but I don't know what to put inside it.


Here's my code for one of my classes
import java.util.Scanner;

public class rectangle
{
    public static void main(String[] args)
    {
        int width;                  
        int height;                 
        int count = 1;

        Scanner scan = new Scanner (System.in);
        
        System.out.println("Please enter the width of the rectangle: ");
        width = scan.nextInt();

        System.out.println("Please enter the height of the rectangle: ");
        height = scan.nextInt();

        while (count <= width)
        {
            if(width < 1 || width > 30)
            {
                throw new IllegalArgumentException("The numbers must be  in range");              
            }
            
            if(height < 1 || height > 30)
            {
                throw new IllegalArgumentException("The numbers must be in range");
            }
            
            for (int star = 1; star <= height; star++)
            {
                System.out.print("*");
            }
            
            System.out.println();
            count++;

        }
    }
}
Now I don't know what to add to make this work from the main method.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 13 2007
Added on Jan 14 2007
34 comments
165 views