天天看點

C語言實驗——求三個整數的最大值

C語言實驗——求三個整數的最大值

Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic

Problem Description

請編寫程式,輸入三個整數,求出其中的最大值輸出。

Input

在一行上輸入三個整數,整數間用逗号分隔。

Output

輸出三個數中的最大值。

Sample Input

5,7,9      

Sample Output

max=9      

Hint

Source

wy    

要考慮正是是兩位以上的情況

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		String str;
	    String[] s = new String[3];
		Scanner input = new Scanner(System.in);
        int a, b, c, t;
        str = input.nextLine();
        s = str.split(",");  //将str以,為分隔符分成若幹字元串;
        a = Integer.parseInt(s[0]);
        b = Integer.parseInt(s[1]);
        c = Integer.parseInt(s[2]);
        t = a;
        if(t < b) {
        	t = b;
        }
        if(t < c) {
        	t = c;
        }
        System.out.println("max="+t);
        
	}
}