JAVA 加减乘除
package homework; import javax.swing.JOptionPane; public class suanshu { public static void main(String agrs[]) { String firstNumber,secondNumber;//定义变量-两个字符串,用于输入数字 int number1,number2;//定义变量-数字 //从屏幕上输入两个数字(字符格式) firstNumber=JOptionPane.showInputDialog("请输入第一个数字"); secondNumber=JOptionPane.showInputDialog("请输入第二个数字"); //将字符串转换为数字 number1=Integer.parseInt(firstNumber); number2=Integer.parseInt(secondNumber); //加减乘除 int jia,jian,cheng,chu; jia=number1+number2; jian=number1-number2; cheng=number1*number2; chu=number1/number2; JOptionPane.showMessageDialog(null,"和为"+jia+"\n"+"差为"+jian+"\n"+"积为"+cheng+"\n"+"商为"+chu,"答案",JOptionPane.PLAIN_MESSAGE); //退出 System.exit(0); } }
最后一步,可用"\n"换行,“答案”代表结果框名称