Java错位了构造

时间:2013-04-22 15:26:57

标签: java construct

我最近在我的Mac上安装了eclipse,我在课堂上一直在玩它。我一直在我的第一个打印行上出现错误的构造错误,并在我的主声明上出现了一堆语法错误。我不确定是什么意思。

 import static java.lang.System.out;
 import java.util.Scanner;


 public static void main (string args[]) 
  {

double a, b, c, d, e, f;

Scanner input = new Scanner();
out.println(" Please enter the first number: ");
a = imput.nextDouble;
out.println("Please enter the second number: ");
b = imput.nextDouble;
out.println ("Please enter the third number : ");
c = imput.nextDouble;
out.println ("Please enter in fourth number : ");
d = imput.nextDouble;
out.println(" Please enter in fifth number : ");
e = imput.nextDouble; 



double sum = a + b + c + d + e;

}

这还没有完成,但据我所知,我拥有所有变量的值,一切都以应有的方式关闭。

3 个答案:

答案 0 :(得分:2)

代码中有许多错误:

  • 没有课堂声明
  • Scanner的错误构造函数调用 - 它不接受空参数
  • nextDouble应该有括号()
  • 当您声明imput 时,
  • input应为input
  • string应为String

以下是更正后的代码:

import static java.lang.System.out;
import java.util.Scanner;

class MyClass {
    public static void main(String args[]) {

        double a, b, c, d, e, f;

        Scanner input = new Scanner(System.in);
        out.println(" Please enter the first number: ");
        a = input.nextDouble();
        out.println("Please enter the second number: ");
        b = input.nextDouble();
        out.println("Please enter the third number : ");
        c = input.nextDouble();
        out.println("Please enter in fourth number : ");
        d = input.nextDouble();
        out.println(" Please enter in fifth number : ");
        e = input.nextDouble();

        double sum = a + b + c + d + e;
        out.println("Sum is : " + sum);
    }
}

答案 1 :(得分:2)

你有几个问题:

  1. 您需要添加课程声明。
  2. 主要参数是String而不是字符串。
  3. imput应为input

答案 2 :(得分:1)

你错过了课堂宣言!在Java 中,所有必须在一个类中。这与C / C ++,Python以及许多支持 functions 的其他语言(Java只有方法)非常不同。

,例如,如果这一切都在名为 MyTest.java 的文件中,那么:

 import static java.lang.System.out;
 import java.util.Scanner;

 public class MyTest {

   public static void main (string args[]) 
    {

  double a, b, c, d, e, f;

  Scanner input = new Scanner();
  out.println(" Please enter the first number: ");
  a = imput.nextDouble;
  out.println("Please enter the second number: ");
  b = imput.nextDouble;
  out.println ("Please enter the third number : ");
  c = imput.nextDouble;
  out.println ("Please enter in fourth number : ");
  d = imput.nextDouble;
  out.println(" Please enter in fifth number : ");
  e = imput.nextDouble; 



  double sum = a + b + c + d + e;
  }
 }