I have a question of the java code. I am currently using netbeans IDE8.2 and I p
ID: 3886656 • Letter: I
Question
I have a question of the java code. I am currently using netbeans IDE8.2
and I put the code
package javaapplication1;
/**
*
* @author
*/
public class JavaApplication1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
double radius;
double PI = 3.14;
System.out.println("Enter the radius : ");
scanner input = new scanner(System.in);
radius = input.nextDouble();
if(radius <=0){
System.out.println("The value entered for radius is invalid. Please enter a positive interger");
} else{
double area = PI*radius*radius;
System.out.println("Area: "+ area);
}
}
}
After I run the code, it says that
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - constructor scanner in class javaapplication1.scanner cannot be applied to given types;
required: no arguments
found: java.io.InputStream
reason: actual and formal argument lists differ in length
at javaapplication1.JavaApplication1.main(JavaApplication1.java:23)
C:UsershomeAppDataLocalNetBeansCache8.2executor-snippets un.xml:53: Java returned: 1
BUILD FAILED (total time: 5 seconds)
would u tell me how to fix?
Explanation / Answer
Hi
I have fixed the issue and highlighted the code changes below
JavaApplication1.java
import java.util.Scanner;
public class JavaApplication1 {
public static void main(String[] args) {
double radius;
double PI = 3.14;
System.out.println("Enter the radius : ");
Scanner input = new Scanner(System.in);
radius = input.nextDouble();
if(radius <=0){
System.out.println("The value entered for radius is invalid. Please enter a positive interger");
} else{
double area = PI*radius*radius;
System.out.println("Area: "+ area);
}
}
}
Output:
Enter the radius :
2.2
Area: 15.197600000000003
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.