英文:
Code printing hello world despite being math
问题
import java.util.Scanner;
class Input {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter your first double: ");
double firstDouble = input.nextDouble();
System.out.print("You entered " + firstDouble + " as your first number.");
System.out.print("Enter your second double: ");
double secondDouble = input.nextDouble();
System.out.print("You entered " + secondDouble + " as your second number.");
System.out.print("Enter your third double: ");
double thirdDouble = input.nextDouble();
System.out.print("You entered " + thirdDouble + " as your third number.");
input.close();
}
}
英文:
I'm trying this on repl.it and it just... prints "hello world" as a default. I don't know exactly what I'm doing wrong.
import java.util.Scanner;
class Input{
public static void mian(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter your first double: ");
double firstDouble = input.nextDouble();
System.out.print("You entered " + firstDouble + " as your first number.");
System.out.print("Enter you second double: ");
double secondDouble = input.nextDouble();
System.out.print("You entered " + secondDouble + " as you second number.");
System.out.print("Enter your third double: ");
double thirdDouble = input.nextDouble();
System.out.print("You entered " + thirdDouble + "As your third number.");
input.close();
}
}
答案1
得分: 1
看起来你的 main 方法被称为 mian。
除此之外,如果你没有改变第一个文件的默认名称,你应该将类命名为 Main,否则 repl.it 将无法编译。
英文:
Looks like your main method is called mian.
Other than that, if you didn't change the default name of the first file, you should name your class Main or repl.it won't compile.
答案2
得分: 0
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter your first double: ");
double firstDouble = input.nextDouble();
System.out.print("You entered " + firstDouble + " as your first number.");
System.out.print("Enter your second double: ");
double secondDouble = input.nextDouble();
System.out.print("You entered " + secondDouble + " as your second number.");
System.out.print("Enter your third double: ");
double thirdDouble = input.nextDouble();
System.out.print("You entered " + thirdDouble + " as your third number.");
input.close();
}
}
尝试这段代码,之前你得到了"Hello World"输出,因为Repl使用了Main.java作为编译程序的名称,但你的程序文件名是Input.java。
英文:
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter your first double: ");
double firstDouble = input.nextDouble();
System.out.print("You entered " + firstDouble + " as your first number.");
System.out.print("Enter you second double: ");
double secondDouble = input.nextDouble();
System.out.print("You entered " + secondDouble + " as you second number.");
System.out.print("Enter your third double: ");
double thirdDouble = input.nextDouble();
System.out.print("You entered " + thirdDouble + "As your third number.");
input.close();
}
}
try this code you was getting hello world because repl compiles program with name of Main.java but your program name is Input.java
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论