Hyunebee
가장 긴 문자 - String 본문
import java.util.Scanner;
public class The_word_in_the_sentence {
public String Solution(String text){
int min = 0;
String result = "";
String[] split = text.split(" ");
System.out.println(split.length);
for (String a : split) {
if(a.length() > min){
min = a.length();
result = a;
}
}
return result;
};
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String text = scanner.nextLine();
The_word_in_the_sentence the_word_in_the_sentence = new The_word_in_the_sentence();
System.out.println(the_word_in_the_sentence.Solution(text));
}
}
주의할점 Array의 index는 1이 아닌 0 부터
'Java > 코테' 카테고리의 다른 글
유효한 팰린드롬 - String (0) | 2022.01.15 |
---|---|
회기 문자열 - String (0) | 2022.01.15 |
특정 문자열만 뒤집기 - String (0) | 2022.01.14 |
단어 뒤집기 - String (0) | 2022.01.14 |
대소문자 - String (0) | 2022.01.14 |