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));
}
}
}
asked Aug 9, 2013 at 22:45
Young Deezie
1452 silver badges12 bronze badges
-
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.Andrew Thompson– Andrew Thompson2013年08月09日 22:47:02 +00:00Commented Aug 9, 2013 at 22:47
2 Answers 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.
answered Aug 9, 2013 at 22:46
rgettman
179k30 gold badges282 silver badges365 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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)
answered Aug 9, 2013 at 22:51
Shamim Ahmmed
8,3836 gold badges28 silver badges37 bronze badges
Comments
lang-java