Java 使用Scanner类获取输入时遇到问题
我正在阅读我的Java教科书,由于某种原因,我无法编译以下代码Java 使用Scanner类获取输入时遇到问题,java,Java,我正在阅读我的Java教科书,由于某种原因,我无法编译以下代码 import java.util.*; public class ComputeAreaWConsoleInput { public static void main (String [] args) { //Create Scanner Obj Scanner sc = New Scanner(System.in); //Get Radius System.out.print("Please
import java.util.*;
public class ComputeAreaWConsoleInput
{
public static void main (String [] args)
{
//Create Scanner Obj
Scanner sc = New Scanner(System.in);
//Get Radius
System.out.print("Please Enter the Radius: ");
double radius = sc.nextdouble();
//determine area
double area = 3.14159 * radius * radius;
//display results
System.out.println("The Area of the Circle w/ radius(" + radius +") is: "
+ area);
}
}
我得到以下错误:
/tmp/java_H98cOI/ComputeAreaWConsoleInput.java:8: error: ';' expected
Scanner sc = New Scanner(System.in);
^
1 error
如何编译代码?您已经编写了:
New Scanner(System.in);
您在New
中的N
是资本
实际关键字是new
,而不是new
解决方案:
将代码行更改为:
new Scanner(System.in);
还有一个错误
应该是:
sc.nextDouble(); // with 'D' capital
而不是
你写过:
New Scanner(System.in);
您在New
中的N
是资本
实际关键字是new
,而不是new
解决方案:
将代码行更改为:
new Scanner(System.in);
还有一个错误
应该是:
sc.nextDouble(); // with 'D' capital
而不是
你写过:
New Scanner(System.in);
您在New
中的N
是资本
实际关键字是new
,而不是new
解决方案:
将代码行更改为:
new Scanner(System.in);
还有一个错误
应该是:
sc.nextDouble(); // with 'D' capital
而不是
你写过:
New Scanner(System.in);
您在New
中的N
是资本
实际关键字是new
,而不是new
解决方案:
将代码行更改为:
new Scanner(System.in);
还有一个错误
应该是:
sc.nextDouble(); // with 'D' capital
而不是
对您的程序进行两项更改 把新的换成新的。换行
Scanner sc = New Scanner(System.in);
到
程序中的另一个错误是扫描双精度扫描。请把双倍改成双倍。所以把下面的行改一下
double radius = sc.nextdouble();
到
它应该很好用 对您的程序进行两次更改 把新的换成新的。换行
Scanner sc = New Scanner(System.in);
到
程序中的另一个错误是扫描双精度扫描。请把双倍改成双倍。所以把下面的行改一下
double radius = sc.nextdouble();
到
它应该很好用 对您的程序进行两次更改 把新的换成新的。换行
Scanner sc = New Scanner(System.in);
到
程序中的另一个错误是扫描双精度扫描。请把双倍改成双倍。所以把下面的行改一下
double radius = sc.nextdouble();
到
它应该很好用 对您的程序进行两次更改 把新的换成新的。换行
Scanner sc = New Scanner(System.in);
到
程序中的另一个错误是扫描双精度扫描。请把双倍改成双倍。所以把下面的行改一下
double radius = sc.nextdouble();
到
它应该很好用 请参见我的评论:以下是您代码的固定版本:
public static void main (String []
{
//Create Scanner Obj
Scanner sc = new Scanner(System.in);
//Get Radius
System.out.print("Please Enter the Radius: ");
double radius = sc.nextDouble();
//determine area
double area = 3.14159 * radius * radius;
//display results
System.out.println("The Area of the Circle w/ radius(" + radius +") is: " + area);
sc.close(); // DO NOT forget this
}
请参阅我的评论:以下是代码的固定版本:
public static void main (String []
{
//Create Scanner Obj
Scanner sc = new Scanner(System.in);
//Get Radius
System.out.print("Please Enter the Radius: ");
double radius = sc.nextDouble();
//determine area
double area = 3.14159 * radius * radius;
//display results
System.out.println("The Area of the Circle w/ radius(" + radius +") is: " + area);
sc.close(); // DO NOT forget this
}
请参阅我的评论:以下是代码的固定版本:
public static void main (String []
{
//Create Scanner Obj
Scanner sc = new Scanner(System.in);
//Get Radius
System.out.print("Please Enter the Radius: ");
double radius = sc.nextDouble();
//determine area
double area = 3.14159 * radius * radius;
//display results
System.out.println("The Area of the Circle w/ radius(" + radius +") is: " + area);
sc.close(); // DO NOT forget this
}
请参阅我的评论:以下是代码的固定版本:
public static void main (String []
{
//Create Scanner Obj
Scanner sc = new Scanner(System.in);
//Get Radius
System.out.print("Please Enter the Radius: ");
double radius = sc.nextDouble();
//determine area
double area = 3.14159 * radius * radius;
//display results
System.out.println("The Area of the Circle w/ radius(" + radius +") is: " + area);
sc.close(); // DO NOT forget this
}
newscanner()->newscanner
,`sc.nextDouble()->sc.nextDouble()`我把工作版本作为一个答案发布。还添加了sc.close()=]Java区分大小写,nextdouble
!=nextDouble
。关于new
和new
new Scanner()->new Scanner
,`sc.nextDouble()->sc.nextDouble()`我将工作版本作为答案发布。还添加了sc.close()=]Java区分大小写,nextdouble
!=nextDouble
。关于new
和new
new Scanner()->new Scanner
,`sc.nextDouble()->sc.nextDouble()`我将工作版本作为答案发布。还添加了sc.close()=]Java区分大小写,nextdouble
!=nextDouble
。关于new
和new
new Scanner()->new Scanner
,`sc.nextDouble()->sc.nextDouble()`我将工作版本作为答案发布。还添加了sc.close()=]Java区分大小写,nextdouble
!=nextDouble
。关于new
和new
也一样。您又犯了一个错误。我也提到过。如果您满意,请接受答案。您又犯了一个错误。我也提到过。如果您满意,请接受答案。您又犯了一个错误。我也提到过。如果您满意,请接受答案。您又犯了一个错误。我也提到过。如果您满意,请接受答案。为什么我需要关闭扫描仪?请查看@Ziggy,这就是为什么您必须始终关闭扫描仪
实例。阅读close()
方法。在同一页**中,当扫描仪关闭时,如果输入源实现可关闭接口,它将关闭输入源。**。如果这对你有效,你能接受我的回答吗?为什么我需要关闭扫描仪?请查看@Ziggy,这就是为什么你必须始终关闭扫描仪
实例。阅读close()
方法。在同一页**中,当扫描仪关闭时,如果输入源实现可关闭接口,它将关闭输入源。**。如果这对你有效,你能接受我的回答吗?为什么我需要关闭扫描仪?请查看@Ziggy,这就是为什么你必须始终关闭扫描仪
实例。阅读close()
方法。在同一页**中,当扫描仪关闭时,如果输入源实现可关闭接口,它将关闭输入源。**。如果这对你有效,你能接受我的回答吗?为什么我需要关闭扫描仪?请查看@Ziggy,这就是为什么你必须始终关闭扫描仪
实例。阅读close()
方法。在同一页**中,当扫描仪关闭时,如果输入源实现可关闭接口,它将关闭输入源。**。如果这对你有效,你能接受我的回答吗?