Java代码实现输入两个整数你n1和n2并求出它们的最大值和最小值
时间: 2024-04-29 11:25:27 浏览: 80
JAVA得到数组中最大值和最小值的简单实例
5星 · 资源好评率100%
```
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入n1:");
int n1 = scanner.nextInt();
System.out.println("请输入n2:");
int n2 = scanner.nextInt();
int max = n1 > n2 ? n1 : n2;
int min = n1 < n2 ? n1 : n2;
System.out.println("最大值为:" + max);
System.out.println("最小值为:" + min);
}
}
```
阅读全文