# 比较IF语句中的多个整数，Java[英] Comparing multiple integers in IF statement, Java

### 问题描述

```int firstInt;
int secondInt;
int thirdInt;
int fourthInt;
int fifthInt;

if (first Int> secondIt, thirdInt, fourthInt, fifthInt)
```

```     if (one > two)
System.out.println("%d is the largest number!", one);

if (one > three)
```

## 推荐答案

```firstInt > secondInt, thirdInt, fourthInt, fifthInt
```

```if ((a >= b) && (a >= c) && (a >= d) && (a >= e)) { // a >= b,c,d,e
System.out.println ("Largest is: " + a);
} else if ((b >= c) && (b >= d) && (b >= e)) {      // b >= c,d,e
System.out.println ("Largest is: " + b);
} else if ((c >= d) && (c >= e)) {                  // c >= d,e
System.out.println ("Largest is: " + c);
} else if (d >= e) {                                // d >= e
System.out.println ("Largest is: " + d);
} else {                                            // e > d
System.out.println ("Largest is: " + e);
}
```

<小时>

```int largest = Math.max(a,Math.max(b,Math.max(c,Math.max(d,e))));
```

<小时>

```int maxOfFive (int a, int b, int c, int d, int e) {
int largest = a;
if (b > largest) largest = b;
if (c > largest) largest = c;
if (d > largest) largest = d;
if (e > largest) largest = e;
return largest;
}
```

```int largest = firstInt;
if (secondInt > largest) largest = secondInt;
if (thirdInt  > largest) largest = thirdInt;
if (fourthInt > largest) largest = fourthInt;
if (fifthInt  > largest) largest = fifthInt;
System.out.println ("Largest is: " + largest);
```