java 对话框输入字符的问题
importjavax.swing.JOptionPane;publicclasslbcom{publicstaticvoidmain(Stringargs[])thro...
import javax.swing.JOptionPane;
public class lbcom
{
public static void main(String args[])throws Exception
{
int a,b;
char c;
a=Integer.parseInt(JOptionPane.showInputDialog("请输入第一个数:"));
b=Integer.parseInt(JOptionPane.showInputDialog("请输入第二个数:"));
c=(char)Integer.parseInt(JOptionPane.showInputDialog("请输入运算符:"));//问题出在这里,不知道怎么写
switch(c)
{
case'+':
JOptionPane.showMessageDialog(null, "结果为:"+(a+b));
break;
case'-':
JOptionPane.showMessageDialog(null, "结果为:"+(a-b));
break;
case'*':
JOptionPane.showMessageDialog(null, "结果为:"+(a*b));
break;
case'/':
JOptionPane.showMessageDialog(null, "结果为:"+(a/b));
break;
default:
JOptionPane.showMessageDialog(null, "无法识别您输入的:"+c);
}
}
} 展开
public class lbcom
{
public static void main(String args[])throws Exception
{
int a,b;
char c;
a=Integer.parseInt(JOptionPane.showInputDialog("请输入第一个数:"));
b=Integer.parseInt(JOptionPane.showInputDialog("请输入第二个数:"));
c=(char)Integer.parseInt(JOptionPane.showInputDialog("请输入运算符:"));//问题出在这里,不知道怎么写
switch(c)
{
case'+':
JOptionPane.showMessageDialog(null, "结果为:"+(a+b));
break;
case'-':
JOptionPane.showMessageDialog(null, "结果为:"+(a-b));
break;
case'*':
JOptionPane.showMessageDialog(null, "结果为:"+(a*b));
break;
case'/':
JOptionPane.showMessageDialog(null, "结果为:"+(a/b));
break;
default:
JOptionPane.showMessageDialog(null, "无法识别您输入的:"+c);
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询