▶ 예시
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine(); // "1234"
char a = s.charAt(2); // "3"
int zeroUse = a - '0';
System.out.println(getUse); // 3
int getUse = Character.getNumericValue(a);
System.out.println(getUse); // 3
}
▶ 예시
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine(); // "JAVA"
char a = s.charAt(2); // "V"
int intNum = a; // 자동형변환
System.out.println(intNum); // 86
byte byteNum = (byte)a; // 수동형변환
System.out.println(byteNum); // 86
}
▶ 예시
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine(); // "JAVA"
char a = s.charAt(2);
System.out.println(a); // "V"
char ary[] = s.toCharArray();
System.out.println(ary); // "JAVA"
}
▶ 예시
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine(); // "1234"
int intNum = Character.getNumericValue(s.charAt(2));
System.out.println(intNum); // 3
}
▶ 예시
import java.nio.charset.StandardCharsets;
public static void main(String[] args) {
int ascii = "a";
System.out.println(ascii); // 97(a)
String s = "Hi";
byte[] bytes = s.getBytes(StandardCharsets.US_ASCII);
System.out.println(bytes[0]); // 72(H)
System.out.println(bytes[1]); // 105(i)
List<Integer> list = s.chars().boxed().collect(Collectors.toList());
System.out.println(list.get(0)); // 72(H)
}
▶ 예시
public static void main(String[] args) {
int num = 97;
char ch = (char)num;
System.out.println(ch); // "a"
String s = Character.toString(num);
System.out.println(s); // "a"
}