如何用验证方法替换无效的方法输入?

时间:2017-10-18 06:01:47

标签: java

如何使我的验证方法替换初始无效输入  一个方法。比如从变量中更改无效的负数  'r' "verify"的新输入import javax.swing.JOptionPane; public class Cylinder { private static final double PI = 3.1416; private double radius; private double height; public Cylinder() { radius = 1.0; height = 1.0; } public Cylinder(double r, double h) { radius = h; height = r; } private double verifyData(double verify, String confirm) { verify = radius; verify = height; while(verify <= 0) { JOptionPane.showMessageDialog(null, "Invalid input"); confirm = JOptionPane.showInputDialog("Enter new value"); verify = Double.parseDouble(confirm); } return verify; } public void setRadius(double r) { radius = r; verifyData(r, null); } public void setHeight(double h) { height = h; } public double getRadius() { return radius; } public double getHeight() { return height; } public double getVolume() { return (PI * Math.pow(radius, 2) * height); } public double getSurfaceArea() { return ((2 * PI * radius * height) + (2 * PI * Math.pow(radius, 2))); } public static double convertInchesToFeet(double r) { return r / 12.0; } } 。感谢。

D = malloc(sizeof(data*));  // allocate memory for a single pointer

0 个答案:

没有答案