When i compile, i get -
MassAndWeight.java:31: error: 'else' without 'if'
else if(weight >= 2000)
^
MassAndWeight.java:35: error: 'else' without 'if'
else
^
2 errors
public class MassAndWeight
{
public static void main(String[] args)
{
// User input
Scanner keyboard = new Scanner(System.in);
double mass;
System.out.print("Enter the object's mass: ");
mass = keyboard.nextDouble();
// Calculate and display
double gravity;
gravity = 9.8F;
double weight;
weight = mass * gravity;
if (weight <= 20)
System.out.print("The object's weight is " + weight + "Newtons.");
System.out.print("The object is too light.");
else if (weight <= 20)
System.out.print("The object's weight is " + weight + "Newtons.");
System.out.print("The object is too light.");
else (weight <= 20)
System.out.print("The object's weight is " + weight + "Newtons.");
System.out.print("The object is too light.");
}
}
Any help is appreciated.