public char charAt(int index) {
if ((index < 0) || (index >= value.length)) {
throw new StringIndexOutOfBoundsException(index);
}
return value[index];
}
원래 char라는 녀석은 배열 index를 리턴한다는 사실을 잊지않을 것!
------------------------------------------------
연수에서 진행한 간단한 코드들
public class list5_8 {
public static void main(String[] args) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try{
System.out.println("飲み物は何が好きですか?");
System.out.println("a オレンジジュース");
System.out.println("b コーヒー");
System.out.println("c どちらでもない");
System.out.println("a,b,cのどれかを選んでください。");
String line = reader.readLine();
//エンターキーを押す時のエラーの方策
if (line.length() == 0) { //line의 길이가 0이면
System.out.println("文字の処理ができなかったです");
return; //단지 처리하고 끝낸다.
}
line.
char c = line.charAt(0);
switch (c) {
case 'a':
System.out.println("オレンジジュースです。");
break;
case 'b':
System.out.println("コーヒーです。");
break;
default:
System.out.println("どちらでもありません。");
}
} catch (IOException e) {
System.out.println(e);
}
}
'Web Dev > JAVA' 카테고리의 다른 글
자바연수) chapter4 두번째문제 (0) | 2015.04.21 |
---|---|
자바연수) chapter4 마지막문제 (0) | 2015.04.21 |
자바연수) chapter4 test2 (0) | 2015.04.21 |
자바연수) chapter4 test1 (0) | 2015.04.21 |
자바연수) 4월16일 (0) | 2015.04.17 |