JAVA_ 求三個整數的最大值(split()用法)

求三個整數的最大值

Time Limit: 1000MS Memory Limit: 65536KB
 

Problem Description

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

Input

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

Output

輸出三個數中的最大值。

Example Input

5,7,9

Example Output

max=9
01 import java.util.*;
02  
03 public class Main {
04         public static void main(String args[]){
05             Scanner input = new Scanner(System.in);
06             String aa = null;
07             aa = input.nextLine();
08             String[] bb = aa.split(",");
09              
10             int max = 0;
11             int[] cc = new int[bb.length];
12             for(int i = 0;i<bb.length;i++){
13                 cc[i] = Integer.parseInt(bb[i]);
14             }
15              
16             for (int i = 0 ; i <cc.length ; i++ ) {
17                  
18                 if(cc[i]>max){
19                     max = cc[i];
20                   }
21             }
22             System.out.println("max="+max);
23         }
24 }
25  

重點:關於split();函數的用法







發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章