我的程序不会显示任何输出

时间:2013-11-09 05:47:22

标签: java

我的代码编译,但输出不会显示。我认为我的方法都是正确的,但我不知道为什么我的输出不会显示。 (注意:Java初学者)

import java.util.Scanner;
import java.lang.Math;

public class Lab8 {

    public static void main(String[] args) {

        double radius;
        double height;

        Scanner in = new Scanner(System.in);
        System.out.print("Enter radius: ");
        radius = in.nextDouble();
        System.out.print("Enter height: ");
        height = in.nextDouble();
    }

    public static double Calculations(double radius, double height) {
        double surfaceArea = (2 * Math.PI * radius * radius) + (2 * Math.PI * radius * height);
        return surfaceArea;
    }

    public static double calculations(double radius, double height) {

        double volume = Math.PI * radius * radius * height;
        return volume;
    }

    public static void output(double surfaceArea, double volume) {
        System.out.println("Surface Area of Cylinder: " + surfaceArea);
        System.out.println("Voulme of Cylinder: " + volume);
    }
}

5 个答案:

答案 0 :(得分:0)

你没有在main(...)内调用任何帮助函数。尝试在主要功能中添加对outputcalculations的通话。

特别喜欢

output(Calculations(radius, height), calculations(radius, height));

可能就足够了。

在学习Java时,开始在函数中应用描述性名称可能会有所帮助,例如CylinderSurfaceArea可以帮助您和任何可能阅读您编写的代码的人保持最低限度的混淆。< / p>

答案 1 :(得分:0)

您实际上并没有调用您的方法。

main中,获得radiusheight后,分别使用适当的参数调用Calculationscalculations

以下是一个例子:

surfaceArea = Calculations(radius, height);
volume = calculations(radius, height);

答案 2 :(得分:0)

您需要在main中调用您的方法来打印值。

   System.out.println("surfacearea " + Calculations(radius,height));
   System.out.println("volume " +calculations(radius,height));
   System.out.println("output "  + output(radius,height));

固定代码:

import java.util.Scanner;
   import java.lang.Math;
   public class Lab8
   {
   public static void main(String[] args)
   {

   double radius;
   double height;

   Scanner in = new Scanner(System.in);
   System.out.print("Enter radius: ");
   radius= in.nextDouble();
   System.out.print("Enter height: ");
   height= in.nextDouble();
   System.out.println("surfacearea " + Calculations(radius,height));
   System.out.println("volume " +calculations(radius,height));
   System.out.println("output "  + output(radius,height));
   }
   public static double Calculations(double radius, double height)
   {
   double surfaceArea= (2 * Math.PI * radius * radius) + (2 * Math.PI *radius* height);           
   return surfaceArea;
   }
   public static double calculations(double radius,double height)
   {

   double volume= Math.PI * radius * radius * height;
   return volume;
   }
   public static void output(double surfaceArea, double volume)
   {
   System.out.println("Surface Area of Cylinder: " + surfaceArea);
   System.out.println("Voulme of Cylinder: " + volume);
    }
      }

答案 3 :(得分:0)

尝试在主方法中调用一个Calculations方法,然后输入如下输入:

System.out.println(Lab8.Calculations(radius,height));

答案 4 :(得分:0)

在main中你错过了计算和输出方法调用

public static void main(String[] args)
{    
   double radius;
   double height;

   Scanner in = new Scanner(System.in);
   System.out.print("Enter radius: ");
   radius= in.nextDouble();
   System.out.print("Enter height: ");
   height= in.nextDouble();
   // call this 
   System.out.println("area " + output(Calculations(radius,height)));
}