
im getting error here..i hav used scanner class for the input at the run time ..and created the object to call the methods...why am i getting error here... can we get output using scanner class , object and methods without using constructor???
//Program to illustrate the classes and objects import java.lang.*; import java.util.*; class Rectangle1 { int length,width; double area,perimeter;
public void calArea()
{
area=length*width;
}
public void calPerimeter()
{
perimeter=2*(length+width);
}
public void display()
{
System.out.println("Length:"+length);
System.out.println("Width:"+width);
System.out.println("Area:"+area);
System.out.println("Perimeter:"+perimeter);
}
public static void main(String args[])
{
Rectangle1 r1=new Rectangle1();
Scanner s=new Scanner(System.in);
System.out.println("enter the length and width");
int l= s.nextInt();
int w=s.nextInt();
r1.calArea();
r1.calPerimeter();
r1.display();
}
}

ANSWER Please
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.