-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP3.java
More file actions
30 lines (24 loc) · 696 Bytes
/
Copy pathP3.java
File metadata and controls
30 lines (24 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package ch1;
import java.util.Scanner;
public class P3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String answer = solution(str);
System.out.println(answer);
}
private static String solution(String str) {
String[] arr = str.split(" ");
String answer = "";
String tmp ="";
int len = arr.length;
for(int i = 0; i< arr.length-1; i++){
if(arr[i].length() >= arr[i+1].length()){
tmp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = tmp;
}
}
return arr[len-1];
}
}