aspose file tools*
The moose likes Beginning Java and the fly likes Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exceptions" Watch "Exceptions" New topic
Author

Exceptions

prans rao
Greenhorn

Joined: Aug 08, 2008
Posts: 9
When i run the program i am getting array index out of bounds exception
at the step of "Integer.parseInt...."
and at the step, where i tried to print the length of "args"
i am getting that "args has zero elements"
and i couldn't enter the values manually at runtime
here is my program:

class Rectangle
{
int length, breadth;
void show(int x, int y)
{
length = x;
breadth = y;
}
int calculate()
{
return(length * breadth);
}
}
public class enter
{
public static void main(String[] args)
{
System.out.println("args has "+args.length+" elements");
Rectangle rectangle = new Rectangle();
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
rectangle.show(a, b);
System.out.println(" you have entered these values : " + a + " and " + b);
int area = rectangle.calculate();
System.out.println(" area of a rectange is : " + area);
}
}
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

here args[] is an array of whatever you entered at command prompt while executing the program , like

c:\>java ClassNameWithMainMethod arg0 arg1 .. argn


And it looks like an homework program , you need to find out solution yourself !


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
i couldn't enter the values manually at runtime

How are you starting your program? Do you know how to enter values on a command line so they can be picked by Java and passed to your program in the String[] args array?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exceptions
 
Similar Threads
array index out of bound problem
ArrayIndexOutOfBoundsException
Exceptions
exceptions
classes and applications