英文:
My nextDouble(); scanner is giving me a "cannott find symbol" error
问题
我正在为我的计算机科学课程做一个项目,但遇到了一个无法继续的问题。我试图做一个非常简单的用户输入问题,但一直出现错误。以下是我的代码和错误信息:
import java.util.*;
public class BeekeepingIncome{
public static void main(String [] args)
{
double rawHoney;
double honeyCombs;
double rent = 534.99;
Scanner scanner = new Scanner(System.in);
System.out.println("购买了多少磅的蜂蜜?");
rawHoney = scanner.nextDouble();
System.out.println("购买了多少磅的蜂巢?");
// 其他代码...
}
}
错误信息如下:
BeekeepingIncome.java:20: 错误: 无法找到符号
rawHoney = scanner.nextDouble();
^
符号: 方法 nextDouble()
位置: 类 BeekeepingIncome
1 个错误
有办法修复这个错误吗?
英文:
I am doing a project for my computer science class and I have run into an issue that wont let me proceed, I ma trying to do a really simple user input question but I keep getting an error. Here is my code and the error:
import java.util.*;
public class BeekeepingIncome{
public static void main(String [] args)
{
double rawHoney;
double honeyCombs;
double rent = 534.99;
Scanner scanner = new Scanner(System.in);
System.out.println("How much honey in pounds was purchased?");
rawHoney = nextdouble();
System.out.println("How many honey combs in pounds were purchased?");
}
}
BeekeepingIncome.java:20: error: cannot find symbol
rawHoney = nextDouble();
^
symbol: method nextDouble()
location: class BeekeepingIncome
1 error
Any way I can fix this?
答案1
得分: 2
你需要使用你的 Scanner
:
rawHoney = scanner.nextDouble();
https://www.w3schools.com/java/java_user_input.asp
https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html
英文:
You need to use your Scanner
:
rawHoney = scanner.nextDouble();
https://www.w3schools.com/java/java_user_input.asp
https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论