importjavax.swing.JOptionPane;publicclassCongzaipublic{publicstaticvoidmain(String[]args){System.out.println("选择输入2个数还是3个数");Scannerreader=newScanner(System.in)...
import javax.swing.JOptionPane;
public class Congzai public {
public static void main (String[] args) {
System.out.println("选择输入2个数还是3个数");
Scanner reader=new Scanner(System.in);
int n = reader.nextInt();
if(n==2)
max(float a,float b);
else if(n==3) max(float a,float b,float c);
else System.out.print("数的个数不正确,请重新输入!");}
public static float max (float a,float b)
{String input1,input2;
int a,b,max;
input1 = JOptionPane.showInputDialog("输入第一个数");
input2 = JOptionPane.showInputDialog("输入第二个数");
a = Integer.parseInt( input1 );
b = Integer.parseInt( input2 );
if(a>b) max = a;
else max=b ;
JOptionPane.showMessageDialog( null, a+","+b+"中的最大数是:"+max,"最大数结果",JOptionPane.PLAIN_MESSAGE );}
public static float max(float a,float b,float c)
{String input1,input2,input3;
int a,b,c,max;
input1 = JOptionPane.showInputDialog("输入第一个数");
input2 = JOptionPane.showInputDialog("输入第二个数");
input3 = JOptionPane.showInputDialog("输入第三个数");
a = Integer.parseInt( input1 );
b = Integer.parseInt( input2 );
c = Integer.parseInt( input3 );
if(a>b)
if(a>c)
max = a;
else
max = c;
else
if(b>c)
max = b;
else
max = c;
JOptionPane.showMessageDialog( null, a+","+b+","+c+"中的最大数是:"+max,"最大数结果",JOptionPane.PLAIN_MESSAGE );
}
}
编译时有错误,没找出来
展开