我是一个初学者,虽然我写的代码编译运行都成功了,但感觉有好多冗余,因为要交书面作业,所以写起来很麻烦。希望高手给个简洁点的或者给我改进一下。这是我写的:importjava.util.Sc...
我是一个初学者,虽然我写的代码编译运行都成功了,但感觉有好多冗余,因为要交书面作业,所以写起来很麻烦。希望高手给个简洁点的或者给我改进一下。这是我写的:
import java.util.Scanner;
public class T24
{
public static void main( String args[] )
{
Scanner input = new Scanner( System.in );
int number1;
int number2;
int number3;
int number4;
int number5;
System.out.print( "Enter first integer: " );
number1 = input.nextInt();
System.out.print( "Enter second integer: " );
number2 = input.nextInt();
System.out.print( "Enter third integer: " );
number3 = input.nextInt();
System.out.print( "Enter fourth integer: " );
number4 = input.nextInt();
System.out.print( "Enter fifth integer: " );
number5 = input.nextInt();
if ( number1
if (number1
if (number1
if ( number1
System.out.print( "number1 is smallest\n");
if ( number2
if (number2
if (number2
if (number2
System.out.print("number2 is smallest\n");
if ( number3
if (number3
if (number3
if (number3
System.out.print("number3 is smallest\n");
if ( number4
if (number4
if (number4
if (number4
System.out.print("number4 is smallest\n");
if ( number5
if (number5
if (number5
if (number5
System.out.print( "number5 is smallest\n");
if ( number1>number2)
if (number1>number3)
if (number1>number4)
if ( number1>number5 )
System.out.print( "number1 is largest\n");
if ( number2>number1)
if (number2>number3)
if (number2>number4)
if (number2>number5 )
System.out.print( "number2 is largest\n" );
if ( number3>number1)
if (number3>number2)
if (number3>number4)
if (number3>number5 )
System.out.print("number3 is largest\n");
if ( number4>number1)
if (number4>number2)
if (number4>number3)
if (number4>number5 )
System.out.print("number4 is largest\n");
if ( number5>number1)
if (number5>number2)
if (number5>number3)
if (number5>number4 )
System.out.print("number5 is largest\n");
}
}
展开