1

What is wrong with my code? I have an error concerning the scanner part of it. I have to add "more details be4 I can post this question, so this is it.

import java.util.Scanner
class rectangle
{
  double width;
  double length;
  double findArea(double a, double b)
  {
    width=a;
    length=b;
    return a*b;
  }
}
public class area
{
  public static void main(String args[])
  {
    {
      System.out.println("Enter the dimensions of the square.");
      Scanner x = new Scanner(System.in);
      Scanner y = new Scanner(System.in);
    }
    {
      rectangle objrect = new rectangle();
      System.out.println(objrect.findArea(x, y));
    }
  }
}
1
  • 1) Always copy/paste error & exception output. 2) Please use the correct spelling for words like 'you', 'your' & 'please'. This makes it easier for people to understand and help. 3) Please learn common Java naming conventions (specifically the case used for the names) for class, method & attribute names & use them consistently. Commented Aug 9, 2013 at 22:47

2 Answers 2

2

You are passing two Scanner objects to a method findArea that expects two double values; that won't work. You should have one Scanner object, with which you should be able to obtain double values that you can pass in to the findArea method.

Sign up to request clarification or add additional context in comments.

Comments

0

Replace the x and y value input line with follows:

Scanner s = new Scanner(System.in);
double x = s.nextDouble();
double y = s.nextDouble();

Now call the method finaArea as follows:

objrect.findArea(x, y)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.