求5个数最大值 java_求简洁的java代码。输入五个数,比较后输出最大值和最小值,用java语言编写...

我是一个初学者,虽然我写的代码编译运行都成功了,但感觉有好多冗余,因为要交书面作业,所以写起来很麻烦。希望高手给个简洁点的或者给我改进一下。这是我写的: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");

}

}

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值