Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners can we use scanner class,class , object and methods to get output without using constructor ????

Have Programming Question? Ask it here!
 
 
 


akshaya
can we use scanner class,class , object and methods to get output without using constructor ????
1 Answer(s)      a year and 3 months ago
Posted in : Java Beginners


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();

}

}


Advertisement
View Answers

December 30, 2012 at 3:47 PM


ANSWER Please



Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com