为什么会提示错误,逻辑哪里有问题。。。。
import javax.swing.JOptionPane;
public class jie3_2_why {
public static void main(String[] args) {
String f1=
JOptionPane.showInputDialog(null,
"请输入第一个数",
JOptionPane.QUESTION_MESSAGE);
String f2=
JOptionPane.showInputDialog(null,
"请输入第二个数",
JOptionPane.QUESTION_MESSAGE);
String f3=
JOptionPane.showInputDialog(null,
"请输入第三个数",
JOptionPane.QUESTION_MESSAGE);
Integer num1 = Integer.getInteger(f1);
Integer num2 = Integer.getInteger(f2);
Integer num3 = Integer.getInteger(f3);
int change = 0;
if(num1 > num2 )//eclipse调试后提示这里有问题。。。。我就是想不明白
{
change = num1;
num1 = num2;
num2 = change;
}
else if(num2 > num3 )
{
change = num2;
num2 = num3;
num3 = change;
}
JOptionPane.showMessageDialog(null, num1+"<="+num2+"<="+num2);
}
}
[解决办法]
public static void main(String[] args) {
String f1=JOptionPane.showInputDialog(null,"请输入第一个数",JOptionPane.QUESTION_MESSAGE);
String f2=JOptionPane.showInputDialog(null,"请输入第二个数",JOptionPane.QUESTION_MESSAGE);
String f3=JOptionPane.showInputDialog(null,"请输入第三个数",JOptionPane.QUESTION_MESSAGE);
Integer num1 = Integer.getInteger(f1);
Integer num2 = Integer.getInteger(f2);
Integer num3 = Integer.getInteger(f3);
System.out.println("num1"+num1);
System.out.println("num2"+num2);
System.out.println("num3"+num3);
int change = 0;
if(num1 > num2 )//eclipse调试后提示这里有问题。。。。我就是想不明白
{
change = num1;
num1 = num2;
num2 = change;
}
else if(num2 > num3 )
{
change = num2;
num2 = num3;
num3 = change;
}
JOptionPane.showMessageDialog(null, num1+"<="+num2+"<="+num2);
}
}
public static void main(String[] args) {
String f1=JOptionPane.showInputDialog("输入乘数" );
String f2=JOptionPane.showInputDialog(null,"请输入第二个数",JOptionPane.QUESTION_MESSAGE);
String f3=JOptionPane.showInputDialog(null,"请输入第三个数",JOptionPane.QUESTION_MESSAGE);
System.out.println("f1:"+f1);
//Integer num1 = Integer.getInteger(f1);
int num1=Integer.parseInt(f1);
int num2=Integer.parseInt(f2);
int num3=Integer.parseInt(f3);
/*Integer num1 = Integer.getInteger(f1);//楼主这些语句写错了
Integer num2 = Integer.getInteger(f2);
Integer num3 = Integer.getInteger(f3);*/
System.out.println("num1:"+num1);
System.out.println("num2:"+num2);
System.out.println("num3:"+num3);
int change = 0;
if(num1 > num2 )//eclipse调试后提示这里有问题。。。。我就是想不明白
{
change = num1;
num1 = num2;
num2 = change;
}
else if(num2 > num3 )
{
change = num2;
num2 = num3;
num3 = change;
}
JOptionPane.showMessageDialog(null, num1+"<="+num2+"<="+num2);
}
}