Reputation: 71
I am working on A Java computing course, and I am stumped on what is causing an error here. I tried to research it but i seems difficult to search for this kind of error.
ERROR: source_file.java:12: error: cannot find symbol
double r = scan.nextDouble; ^
symbol: variable nextDouble
location: variable scan of type Scanner
Code:
import java.io.*;
import static java.lang.System.*;
import java.util.Scanner;
class Rextester{
public static void main (String str[]) throws IOException {
Scanner scan = new Scanner(System.in);
System.out.println("Radius:");
double r = scan.nextDouble;
double circumference = (2 * 3.14 * r);
double area = (r * r * 3.14);
System.out.println("Circumference: " + circumference );
System.out.println("Area :" + area );
}
}
Upvotes: 0
Views: 221
Reputation: 2613
ERROR: source_file.java:12: error: cannot find symbol double r = scan.nextDouble;
this error means that you try to access a public element of the object that is hold in the variable scan
.
What you want to call is not a public variable but the method nextDouble()
Therefor you must use scan.nextDouble();
to call the method.
Upvotes: 3
Reputation: 28588
nextDouble() is a method not property
so try:
double r = scan.nextDouble();
try to shorten your code:
public static void main (String str[]) throws IOException {
Scanner scan = new Scanner(System.in);
double r = scan.nextDouble();
System.out.println("Circumference: " + (2 * Math.PI * r));
System.out.println("Area :" + (r * r * Math.PI));
}
Upvotes: 0
Reputation: 2408
Little side note, apart from
scan.nextDouble();
you should also use
Math.PI
instead of 3.14
Fixed code:
import java.io.*;
import static java.lang.System.*;
import java.util.Scanner;
class Rextester{
public static void main (String str[]) throws IOException {
Scanner scan = new Scanner(System.in);
System.out.println("Radius:");
double r = scan.nextDouble();
double circumference = (2 * Math.PI * r);
double area = (r * r * Math.PI);
System.out.println("Circumference: " + circumference );
System.out.println("Area :" + area );
}
}
Upvotes: 0
Reputation: 1017
change your line to double r = scan.nextDouble();
instead of double r = scan.nextDouble
Upvotes: 1
Reputation: 13566
change scan.nextDouble
to scan.nextDouble()
. It is a method and not field. So it requires brackets.
Upvotes: 0