2016-10-23 9 views
0

Я не знаю, что у меня неправильно, но он не будет компилироваться. Сообщение об ошибке я получаю/«еще» без «если»// не заявление// «еще» без «если»/Что я делаю неправильно в этой программе?

Я делаю это именно как образец на мою домашнюю работу показывает, и я все еще получаю эту ошибку. Пожалуйста, помогите мне с Math.PI. Я полностью потерян.

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."); 
     } 

    } 
} 
+1

Удалите точку с запятой от 'если (выбор == 1); {...}' и другие – janos

+0

Нет точки с запятой после того, как операторы используют скобки, чтобы обернуть код 'if {}' –

ответ

1

Вы не ставите точку с запятой после if (choice == 1); правильный способ сделать это ...

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."); 
} 
+0

Спасибо за это! Но первый радиус - причина, по которой он не компилируется. – Ani

+0

Кроме того, это не округление до четвертого знака после запятой, как я думал, я запрограммировал его. – Ani

+0

@Ani: использовать форматирование валюты. – Charles

Смежные вопросы