JAVA/String class
String 예제(1)
by pms93
2022. 7. 21.
package strings;
public class Quiz01 {
public static void main(String[] args) {
// Quiz1
// Have a nice day Have a nice day Have a nice day
// 위 문자열에서 a의 위치를 '저장하여' 출력
// 결과 : 1, 5, 13 ,17, 21, 29, 33, 37, 45
String ex = "Have a nice day Have a nice day Have a nice day";
int array[] = new int[ex.length()];
int arrayCnt = 0;
for (int cnt = 0; cnt < ex.length(); cnt++)
if (ex.charAt(cnt) == 'a')
array[arrayCnt++] = cnt;
for (int n : array) {
if (n == 0)
break;
System.out.println(n);
}
}
}