wood burning stoves*
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
Reply locked New topic
Author

Exceptions

prans rao
Greenhorn

Joined: Aug 08, 2008
Posts: 9
Sorry to the teachers who replied me
thanks a lot

As you said i have changed the spelling of "length" and compliled it successfully.
But now the problem is with Exception.
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);
}
}
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18529
    
  40

Please do *not* start a new topic for each response to an on-going toopic !! Not only is it completely confusing, you lose details which may be useful.

For the record, this topic is a followup to the topic linked below, which I am recommending that you followup to. This topic I will now close.

http://www.coderanch.com/t/411426/java/java/beginner

Henry
[ August 08, 2008: Message edited by: Henry Wong ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
 
subject: Exceptions
 
Similar Threads
array index out of bound problem
Exceptions
exceptions
classes and applications
ArrayIndexOutOfBoundsException