java 查找n个输入的最大值

java

//find greatest among n numbers

import java.util.Scanner;

public class Numbers {

public static void main(String[] args) {

int n, temp, max = Integer.MIN_VALUE;

Scanner ip = new Scanner(System.in);

System.out.print("Enter the number of inputs: ");

n = ip.nextInt();

for (int i = 1; i <= n; i++) {

System.out.print("Enter number " + i + ": ");

temp = ip.nextInt();

if (temp >= max)

max = temp;

}

System.out.println("The greatest number is " + max);

ip.close();

}

}

OUTPUT:

Enter the number of inputs: 5

Enter number 1: 3

Enter number 2: 7

Enter number 3: 2

Enter number 4: 6

Enter number 5: 9

The greatest number is 9

以上是 java 查找n个输入的最大值 的全部内容, 来源链接: utcz.com/z/392784.html

回到顶部