import java.io.*;
import java.util.*;
public class volumeConeD
{//class
public static void main (String [] args)
{//main
Scanner keyBoard = new Scanner(System.in);//input for keyBoard
//variables
double volume;
double radius;
double hieght;
double oneThird = 0.3333;
double pie = 3.14;
double yes = 1.0;
boolean r = true;
try
{//begin of try
while(r == true){
System.out.print("Volume of a Cone... V=1/3(3.14)r^2(h)");
System.out.println ();
System.out.println ();
radius = getRadius(radius);//call to method
radius = keyBoard.nextDouble ();
System.out.print("Enter a Height ");
hieght = keyBoard.nextDouble ();
//math
volume = oneThird * pie * radius * radius * hieght;
System.out.printf ("Volume = " + volume);
}//end of try
catch (Exception Error){
System.out.println("You entered wrong data");
}
System.out.println ();
System.out.print("Does the user wish to try again?");
System.out.println ();
System.out.print("Enter 1 to go again OR any other key to end.");
yes = keyBoard.nextDouble();
}//end of while
}//end of main
public static double getRadius(double mRadius)
{
System.out.print("Enter Radius Squared Number ");
return mRadius;
}
}//end of program
这是我第一次在这个论坛上发帖,所以请原谅如何问...这里去...我想要做的就是使用哨兵方法(while 循环)在用户控制下重复这个问题。我几乎早点就开始工作了,但我不断收到关于我如何定义“r”的错误。现在我收到关于我的 catch 尝试块的错误。请帮忙。
volumeConeD.java:35: error: 'catch' without 'try'
catch (Exception Error){
^
volumeConeD.java:35: error: ')' expected
catch (Exception Error){
^
volumeConeD.java:35: error: not a statement
catch (Exception Error){
^
volumeConeD.java:35: error: ';' expected
catch (Exception Error){
^
volumeConeD.java:19: error: 'try' without 'catch', 'finally' or resource declarations
try
^
5