代码打印”Hello World”尽管是数学相关的

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

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

huangapple
  • 本文由 发表于 2020年5月30日 23:19:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/62104531.html
匿名

发表评论

匿名网友

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

确定