-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP3Answer2.java
More file actions
33 lines (29 loc) · 805 Bytes
/
Copy pathP3Answer2.java
File metadata and controls
33 lines (29 loc) · 805 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
31
32
33
package ch1.p3;
import java.util.Scanner;
public class P3Answer2 {
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 answer = "";
int pos;
int max = Integer.MIN_VALUE;
int min =0;
while((pos = str.indexOf(' ')) != -1){
String tmp = str.substring(0,pos);
min = answer.length();
if(max < min){
max = min;
answer = tmp;
}
str = str.substring(pos+1);
}
if(str.length() > max){
answer = str;
}
return answer;
}
}