C语言实验——求三个整数的最大值
Time Limit: 1000 ms
Memory Limit: 65536 KiB
Problem Description
请编写程序,输入三个整数,求出其中的最大值输出。
Input
在一行上输入三个整数,整数间用逗号分隔。
Output
输出三个数中的最大值。
Sample Input
5,7,9
Sample Output
max=9
import java.util.Scanner; public class Main{ public static void main(String args[]) { Scanner cin = new Scanner(System.in); String s1 = cin.nextLine(); String[] s2 = s1.split(",");//将s1用逗号分隔,放到s2数组中 int a = Integer.parseInt(s2[0]);//将字符串变成整数 int b = Integer.parseInt(s2[1]); int c = Integer.parseInt(s2[2]); int max = a; if(max<b) max = b; if(max<c) max = c; System.out.println("max="+max); } }