Reputation: 145
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));
}
}
}
Upvotes: 1
Views: 93
Reputation: 8383
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)
Upvotes: 0
Reputation: 178253
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.
Upvotes: 2