I recently installed eclipse on my mac and I was fooling around with it in class. I keep getting misplaced construct errors on my first print line and a bunch on syntax error on my main declaration. I'm not really sure whats up.
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;
}
This isn't finished but as far as I can see I have values for all my variables and everything is closed the way it should be.
There are many errors in the code:
Scanner
- it doesn't accept empty argumentsimput
should be input
, as you declared input
Here's the corrected code:
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);
}
}