My nextDouble(); scanner is giving me a “找不到符号” 错误

huangapple go评论110阅读模式
英文:

My nextDouble(); scanner is giving me a "cannott find symbol" error

问题

我正在为我的计算机科学课程做一个项目,但遇到了一个无法继续的问题。我试图做一个非常简单的用户输入问题,但一直出现错误。以下是我的代码和错误信息:

  1. import java.util.*;
  2. public class BeekeepingIncome{
  3. public static void main(String [] args)
  4. {
  5. double rawHoney;
  6. double honeyCombs;
  7. double rent = 534.99;
  8. Scanner scanner = new Scanner(System.in);
  9. System.out.println("购买了多少磅的蜂蜜?");
  10. rawHoney = scanner.nextDouble();
  11. System.out.println("购买了多少磅的蜂巢?");
  12. // 其他代码...
  13. }
  14. }

错误信息如下:

  1. BeekeepingIncome.java:20: 错误: 无法找到符号
  2. rawHoney = scanner.nextDouble();
  3. ^
  4. 符号: 方法 nextDouble()
  5. 位置: BeekeepingIncome
  6. 1 个错误
  7. 有办法修复这个错误吗?
英文:

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:

  1. import java.util.*;
  2. public class BeekeepingIncome{
  3. public static void main(String [] args)
  4. {
  5. double rawHoney;
  6. double honeyCombs;
  7. double rent = 534.99;
  8. Scanner scanner = new Scanner(System.in);
  9. System.out.println("How much honey in pounds was purchased?");
  10. rawHoney = nextdouble();
  11. System.out.println("How many honey combs in pounds were purchased?");
  12. }
  13. }
  14. BeekeepingIncome.java:20: error: cannot find symbol
  15. rawHoney = nextDouble();
  16. ^
  17. symbol: method nextDouble()
  18. location: class BeekeepingIncome
  19. 1 error

Any way I can fix this?

答案1

得分: 2

你需要使用你的 Scanner

  1. 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:

  1. rawHoney = scanner.nextDouble();

https://www.w3schools.com/java/java_user_input.asp

https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html

huangapple
  • 本文由 发表于 2020年8月5日 11:41:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/63258077.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定