indexOf2 [알고리즘] 중복문자 제거 with Java, indexOf(s.charAt(c)) 오늘 배운 것 1. 중복 문자열 판별하기 문자열 리스트 중 한 문자의 위치 == for문의 인덱스 i인 경우 해당 문자열이 첫번째로 나온 것임을 확인할 수 있다. 예를들어 test라는 문자열이 존재할 때, 아래의 표와 같이 마지막 T는 번호가 같지 않음을 확인할 수 있다. 이것은 중복 문자열이라고 하고 추가하지 않아야 한다. 2. 문제 풀이 import java.util.Scanner; public class Main { public static String solution(String str) { String answer = ""; for (int i = 0; i < str.length(); i++) { if(str.indexOf(str.charAt(i)) == i){ answer += str.char.. 2022. 2. 25. [알고리즘] 문장 속 단어 with Java, nextLine(), indexOf(),subString() 알고리즘 공부 2일차 ! 오늘도 화이팅 해보자. 오늘 배운 것 1. nextLine() next()가 문자열을 읽는 것(띄어쓰기 전까지) 이라면, nextLine()은 한줄을 그대로 읽는 것이다. // test = "it is time to study"; System.out.println(test.next());// it System.out.println(test.nextLine());// it is time to study 2. indexOf(char c) param으로 주어진 문자의 첫번째 인덱스를 반환한다. 없다면 -1을 반환해준다. String test = "it is time to study"; System.out.println(test.indexOf('i'));// 0 System.out.pr.. 2022. 2. 24. 이전 1 다음