코딩테스트가 알고 보니 IDE와 같은 것들을 못 쓰고 단축키도 못 쓴다는 것을 알게 되었다. 그래서 기존에 해왔던 이클립스로 푸는 방식을 바꿔서 백준이나 프로그래머스와 같은 사이트에서만 풀어야겠다.
그 첫번째 문제로
[백준 11654]
처음 작성했던 코드
import java.util.*;
public class Main{
Scanner sc = new Scanner(System.in);
String word = sc.nextString();
Int num = word.parseInt();
System.out.println(num);
}
문제점
next();
- 공백문자까지 입력받음nextLine();
- 줄 단위로 입력받음Integer.parseInt(str);
Integer.toString(int);
공부할 개념
charAt(i)
-> String문자열의 i번째 문자를 char형으로 바꿔줌char
형 문자를 int
변수로 저장하여 ASCII코드를 사용import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String word = sc.next();
int num = word.charAt(0);
System.out.println(num);
}
}