英文:
Java - compilation error - cannot find symbol - variable Terminal
问题
我刚开始学习Java。在编译以下代码时遇到了问题。
public class Conversion {
public static void main(String[] args) {
double euros;
double dollars;
System.out.println("欧元总数?");
euros = Terminal.lireDouble();
dollars = euros * 1.118;
System.out.println("美元总数:");
System.out.println(dollars);
}
}
我得到了以下错误信息:
/Users/Mathieu/IdeaProjects/Conversion/src/com/company/Conversion.java:9:17
java: 找不到符号 符号: 变量 Terminal 位置:
类 com.company.Conversion
请问你能帮我吗?我的代码有什么问题吗?
提前谢谢你。
英文:
I have just started learning Java for first time.
I have an issue when compiling the following code.
public class Conversion {
public static void main (String[] args) {
double euros;
double dollars;
System.out.println("Sum in euros? ");
euros = Terminal.lireDouble();
dollars = euros * 1.118;
System.out.println("Sum in dollars: ");
System.out.println(dollars);
}
}
I get the following error message:
> /Users/Mathieu/IdeaProjects/Conversion/src/com/company/Conversion.java:9:17
> java: cannot find symbol symbol: variable Terminal location:
> class com.company.Conversion
Please, could you help me ?
What is wrong with my code.
Thank you in advance
答案1
得分: 1
为了从用户获取输入,请使用以下代码:
import java.util.Scanner;
public class Conversion {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double euros;
double dollars;
System.out.println("请输入欧元金额:");
euros = in.nextDouble();
dollars = euros * 1.118;
System.out.println("美元金额为:");
System.out.println(dollars);
}
}
Scanner用于从用户获取输入。
英文:
In order to get input from the user use this
import java.util.Scanner;
public class Conversion {
public static void main (String[] args) {
Scanner in = new Scanner(System.in);
double euros;
double dollars;
System.out.println("Sum in euros? ");
euros = in.nextDouble();
dollars = euros * 1.118;
System.out.println("Sum in dollars: ");
System.out.println(dollars);
}
}
Scanner is used to get input from the user
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论