-3
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 pie = 3.14;
        double yes = 1.0;
        boolean volumeTwo = true;


        while(volumeTwo == 0){
            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
            System.out.print("Enter a Height      ");
            hieght = keyBoard.nextDouble ();
            //math
            volume = .33333 * pie * radius * radius * hieght;
            System.out.printf ("Volume =       " + volume);

        }//end of while         
    }//end of main
    public static double getRadius (double radius)
    {
        Scanner keyBoard = new Scanner(System.in);

        System.out.print("Enter Radius Squared Number      "); 
        radius = keyBoard.nextDouble ();
        return radius;
    }
}//end of program

所以这是我的问题。我必须写这个,以便如果答案最终是 Volume = 0 程序必须结束。我必须使用 while 循环和该方法来输入半径。我不断收到这个错误,我不知道为什么。

               error
                       volumeConeD.java:25: error: incomparable types: boolean and int
while(volumeTwo == 0){
                ^
1 error.

我理解错误的含义,但我不知道如何修复它。请帮助新编辑......也在它必须读取的while循环中,while(Volume == 0)。

4

4 回答 4

1

如果while(volumeTwo)您希望它在volumeTwois时继续,true或者while(!volumeTwo)如果您希望它在volumeTwois时继续,请使用false

于 2013-09-14T17:48:36.960 回答
0

你试着比较一下boolean0

boolean volumeTwo = true;
while(volumeTwo == 0)

利用

 while(volumeTwo == true)

或者

while(volumeTwo)  
于 2013-09-14T17:48:01.073 回答
0

volumeTwo彻底摆脱。您关心是否volume为 0,因此只需将 while 循环更改为while(volume!=0)并确保将卷初始化为 0 以外的值。

于 2013-09-14T18:25:33.837 回答
-1

我认为以下是您想要实现的目标。请参阅标有 ​​<======= 的评论:

    ... 
    //boolean volumeTwo = true; // <======= Manoj - COMMENT THIS LINE  
    double volumeTwo = 1.0; // <=========== Manoj - any non-zero for that matter
    ... 

    ... 
    while(volumeTwo != 0.0){
    ... 
              //math
      volume = .33333 * pie * radius * radius * hieght;
      System.out.printf ("Volume =       " + volume);
      volumeTwo = volume; // <=============== Manoj - update volumeTwo with calculated volume 
                          // <===============       - when volumeTwo becomes 0.0 loop quits 
于 2013-09-14T17:57:33.070 回答