-
[JAVA] CodingTest 문제 3번 - ex2카테고리 없음 2022. 11. 8. 17:50
package day1031.CodingTest;
import java.util.Scanner;
public class main03_1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = "apple";
char[] ss = new char[s.length()];
System.out.println("알파벳 입력");
String in = sc.next();
char input = in.charAt(0);
boolean b = false;
for (int i = 0; i < s.length(); i++) {
ss[i] = s.charAt(i);
}
for(int i = 0; i<ss.length; i++) {
if(input == ss[i]) {
System.out.println(i);
b = true;
}
}
if (b = false)
{
System.out.println(-1);
}
}
}char at 메서드를 활용했습니다.