0

I don't know what I have wrong here but it will not compile. The error message I get is /"else" without "if"/ /not a statement/ /"else" without "if"/

I am doing it exactly how the sample on my homework shows and I am still getting this error. Please someone help me with Math.PI. I am totally lost.

import java.util.Scanner;

import java.text.DecimalFormat;

public class CircleCalc

{

   public static void main(String[]args)

   {
      Scanner keyboard = new Scanner(System.in);
      double radius;
      double area = Math.PI * radius * radius;
      double circum = 2 * radius * Math.PI;
      DecimalFormat formatter = new DecimalFormat("#0.0000");
      int choice;

      System.out.println("CIRCLE CALCULATOR MENU");
      System.out.println("1) Calculate the Area of a Circle");
      System.out.println("2) Calculate the CIrcumference of a Circle");
      System.out.println("3) Quit the Program");
      System.out.println("Make a selection by choosing a number:");
      choice = keyboard.nextInt();

      if (choice == 1);
      {
         radius = 105.7;
         System.out.println(" The Area of the Circle with radius 105.7 is " + area);
      }

      else if (choice == 2);
      {
         radius = 62.7;
         System.out.println("The Circumference of the Circle with radius 62.7 is " + circum);
      }

      else if (choice == 3);
      {
      System.out.println("You have chosen to quit the program.");
      }

   }
}
Ani
  • 1

1 Answers1

1

You don't put semicolons after if (choice == 1); The correct way to do it is...

if (choice == 1)
{
    radius = 105.7;
    System.out.println(" The Area of the Circle with radius 105.7 is " + area);
}

else if (choice == 2)
{
    radius = 62.7;
    System.out.println("The Circumference of the Circle with radius 62.7 is " + circum);
 }

 else if (choice == 3)
 {
     System.out.println("You have chosen to quit the program.");
 }
Charles
  • 1,384
  • 11
  • 18