Win a copy of Design for the Mind this week in the Design forum!
    Bookmark Topic Watch Topic
  • New Topic

Exceptions

 
prans rao
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Marshal
Pie
Posts: 21003
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
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 ]
 
    Bookmark Topic Watch Topic
  • New Topic