我写的简单程序,怎么老是编译不过去啊。帮忙看看
来源: 互联网 发布时间:2015-09-16
本文导语: import javax.swing.JOptionPane; public class Q18{ public static void main (String args[]){ String fNo,sNO,tNo; int no1,no2,no3,s1,s2,s3,min,max; fNo = JOptionPane.showInputDialog("请输入第一个...
import javax.swing.JOptionPane;
public class Q18{
public static void main (String args[]){
String fNo,sNO,tNo;
int no1,no2,no3,s1,s2,s3,min,max;
fNo = JOptionPane.showInputDialog("请输入第一个整数");
sNo = JOptionPane.showInputDialog("请输入第二个整数");
tNo = JOptionPane.showInputDialog("请输入第三个整数");
no1 = Integer.parseInt(fNo);
no2 = Integer.parseInt(sNo);
no3 = Integer.parseInt(tNo);
s1 = no1+no2+no3;
s2 = no1*no2*no3;
s3 = s1/3;
if (no1>=no2)
max = no1;
if (no1max)
max = no3;
if (min>no3)
min = no3;
JOptionPane.showMessageDialog(null,s1,"和=",s2,"积=",s3,"平均数=",max,"最大数是",min,"最小数是",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
(实现的功能是:从键盘输入3个数,在一个信息对话框中显示3个数的和,积,平均数,最大数,最小数,(gui技术))
public class Q18{
public static void main (String args[]){
String fNo,sNO,tNo;
int no1,no2,no3,s1,s2,s3,min,max;
fNo = JOptionPane.showInputDialog("请输入第一个整数");
sNo = JOptionPane.showInputDialog("请输入第二个整数");
tNo = JOptionPane.showInputDialog("请输入第三个整数");
no1 = Integer.parseInt(fNo);
no2 = Integer.parseInt(sNo);
no3 = Integer.parseInt(tNo);
s1 = no1+no2+no3;
s2 = no1*no2*no3;
s3 = s1/3;
if (no1>=no2)
max = no1;
if (no1max)
max = no3;
if (min>no3)
min = no3;
JOptionPane.showMessageDialog(null,s1,"和=",s2,"积=",s3,"平均数=",max,"最大数是",min,"最小数是",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
(实现的功能是:从键盘输入3个数,在一个信息对话框中显示3个数的和,积,平均数,最大数,最小数,(gui技术))
|
错误1:未定义sNo,注意你的String fNo,sNO,tNo;,此处sNo最后写成了0,不是o,改正为:String fNo,sNo,tNo;
错误2:JOptionPane.showMessageDialog(null,s1,"和=",s2,"积=",s3,"平均数=",max,"最大数是",min,"最小数是",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog不存在如上构造器模式
错误3:max,min变量可能得不到正确的赋值,而且你的程序逻辑上存在错误;
整体改正如下,逻辑错误未改正,如最小值min没有得到正确的赋值等,自个检验吧
package Alpha;
import javax.swing.JOptionPane;
public class newTest{
public static void main (String args[]){
String fNo,sNo,tNo;
int no1,no2,no3,s1,s2,s3,min,max;
fNo = JOptionPane.showInputDialog("请输入第一个整数");
sNo = JOptionPane.showInputDialog("请输入第二个整数");
tNo = JOptionPane.showInputDialog("请输入第三个整数");
no1 = Integer.parseInt(fNo);
no2 = Integer.parseInt(sNo);
no3 = Integer.parseInt(tNo);
s1 = no1+no2+no3;
s2 = no1*no2*no3;
s3 = s1/3;
max = 0;
min = 0;
if (no1>=no2)
max = no1;
if (no1max)
max = no3;
if (min>no3)
min = no3;
String title ="";
String msg = "和=" +s1+ ";" + "积=" +s2+ ";" + "平均数=" +s3+ ";" + "最大数是" +max+";"+"最小数是"+min;
JOptionPane.showMessageDialog(null,msg,title,JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
错误2:JOptionPane.showMessageDialog(null,s1,"和=",s2,"积=",s3,"平均数=",max,"最大数是",min,"最小数是",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog不存在如上构造器模式
错误3:max,min变量可能得不到正确的赋值,而且你的程序逻辑上存在错误;
整体改正如下,逻辑错误未改正,如最小值min没有得到正确的赋值等,自个检验吧
package Alpha;
import javax.swing.JOptionPane;
public class newTest{
public static void main (String args[]){
String fNo,sNo,tNo;
int no1,no2,no3,s1,s2,s3,min,max;
fNo = JOptionPane.showInputDialog("请输入第一个整数");
sNo = JOptionPane.showInputDialog("请输入第二个整数");
tNo = JOptionPane.showInputDialog("请输入第三个整数");
no1 = Integer.parseInt(fNo);
no2 = Integer.parseInt(sNo);
no3 = Integer.parseInt(tNo);
s1 = no1+no2+no3;
s2 = no1*no2*no3;
s3 = s1/3;
max = 0;
min = 0;
if (no1>=no2)
max = no1;
if (no1max)
max = no3;
if (min>no3)
min = no3;
String title ="";
String msg = "和=" +s1+ ";" + "积=" +s2+ ";" + "平均数=" +s3+ ";" + "最大数是" +max+";"+"最小数是"+min;
JOptionPane.showMessageDialog(null,msg,title,JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
|
其实没什么大错误,你按照错误信息修改就好了。下面的是我修改的结果,可以达到你说的目的:
import javax.swing.JOptionPane;
public class Q18{
public static void main (String args[]){
String fNo,sNo,tNo;
int no1,no2,no3,s1,s2,s3,min = 0 ,max = 0;
fNo = JOptionPane.showInputDialog("请输入第一个整数");
sNo = JOptionPane.showInputDialog("请输入第二个整数");
tNo = JOptionPane.showInputDialog("请输入第三个整数");
no1 = Integer.parseInt(fNo);
no2 = Integer.parseInt(sNo);
no3 = Integer.parseInt(tNo);
s1 = no1+no2+no3;
s2 = no1*no2*no3;
s3 = s1/3;
max = Math.max(no1,Math.max(no2,no3));
min = Math.min(no1,Math.min(no2,no3));
JOptionPane.showMessageDialog(null,"和="+s1+",积="+s2+",平均数="+s3+",最大数是"+max+",最小数是"+min,"结果",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
import javax.swing.JOptionPane;
public class Q18{
public static void main (String args[]){
String fNo,sNo,tNo;
int no1,no2,no3,s1,s2,s3,min = 0 ,max = 0;
fNo = JOptionPane.showInputDialog("请输入第一个整数");
sNo = JOptionPane.showInputDialog("请输入第二个整数");
tNo = JOptionPane.showInputDialog("请输入第三个整数");
no1 = Integer.parseInt(fNo);
no2 = Integer.parseInt(sNo);
no3 = Integer.parseInt(tNo);
s1 = no1+no2+no3;
s2 = no1*no2*no3;
s3 = s1/3;
max = Math.max(no1,Math.max(no2,no3));
min = Math.min(no1,Math.min(no2,no3));
JOptionPane.showMessageDialog(null,"和="+s1+",积="+s2+",平均数="+s3+",最大数是"+max+",最小数是"+min,"结果",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}