?? boxtest.java
字號:
//BoxTest.java
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
class Box{
private double length;
private double width;
private double high;
public Box(){
length=1;
width=1;
high=1;
}
public Box(double a,double b,double c){
if(a<=0||b<=0||c<=0){
System.out.println("invalid input");
System.exit(0);
}
else{
length=a;
width=b;
high=c;
}
}
public double getVolume(){
return(length*width*high);
}
public double getLength(){
return length;
}
public double getWidth(){
return width;
}
public double getHigh(){
return high;
}
}
public class BoxTest{
public static void main(String args[]){
Box box=new Box(1.5,2.4,3);
DecimalFormat twoDigits=new DecimalFormat("0.00");
String output="The length of box is:"+twoDigits.format(box.getLength())
+"\nThe width of box is:"+twoDigits.format(box.getWidth())
+"\nThe high of box is:"+twoDigits.format(box.getHigh())
+"\nThe volume of box is:"+twoDigits.format(box.getVolume());
JOptionPane.showMessageDialog(null,output,"Box Test",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -