本文共 477 字,大约阅读时间需要 1 分钟。
import java.util.Scanner;public class Max { //输入3个数字,求最大值并输出 public static void main(String[] args) { // 读取键盘输入信息 Scanner s = new Scanner(System.in); // 提示输入3个数字 System.out.println("请输入3个数字"); // 定义a,b,c的值 int a = s.nextInt(); int b = s.nextInt(); int c = s.nextInt(); // 声明最大值为max int max; // 比较a和b最大的值为max if (a > b) { max = a; } else { max = b; } // a和b中的最大值max再和c比较,若比c小,则max为c if (c > max) { max = c; } // 输出结果 System.out.println("最大值是" + max); }}
转载地址:http://qvnwi.baihongyu.com/