1 import javax.swing.JOptionPane; 2 public class Acceleration { 3 public static void main(String[] args){ 4 double v0,v1,t,a; 5 String number; 6 number=JOptionPane.showInputDialog(null,"输入初速度"); 7 v0=Double.parseDouble(number); 8 number=JOptionPane.showInputDialog(null,"输入末速度"); 9 v1=Double.parseDouble(number); 10 number=JOptionPane.showInputDialog(null,"输入时间"); 11 t=Double.parseDouble(number); 12 a=(v1-v0)/t; 13 int messageType=JOptionPane.INFORMATION_MESSAGE; 14 String message="The average acceleration is " + a; 15 JOptionPane.showMessageDialog(null,message,"result",messageType ); 16 } 17 }