728x90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
public class IndexOfTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
String s;
System.out.println("문장입력 : ");
s = sc.next();
int index = s.indexOf("A"); //A가 몇번째에 있는지 반환(정수형)
char c = s.charAt(0); //0번째 문자를 반환(캐릭터형)
if (index == -1)
System.out.println("A는 없습니다.");
else
System.out.println("A는 " + (index + 1) + "번째에 있습니다 ");
System.out.println("첫번째 문자는" + c + "입니다");
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
charAt(), indexOf()의 차이점
charAt() |
indexOf() |
|
괄호안 |
int |
char |
반환 |
char |
int |
[이외 메소드]
toUpperCase() : 문자열을 다 대문자로 바꿔줌
compareTo(String another string) : 문자열이 같으면 0리턴, 이 문자열이 another string보다 사전에 먼저 나오면 음수리턴/더 나중에 나오면 양수리턴
equals() : 같으면 true, 다르면 false반환
'programming > java' 카테고리의 다른 글
[java] 자바 기초 문법과 클래스의 구성 (0) | 2020.12.31 |
---|---|
이클립스 설치 및 기본설정 (0) | 2020.12.21 |
[java] 파일 입출력 (0) | 2020.06.13 |
java - Double형 배열과 출력(toString(),for-each) (0) | 2019.10.09 |
java ArrayList - add(), get(), remove()정리 (0) | 2019.10.08 |
댓글