12단원 클리어!
- System.out.println은 들어오는 String 인스턴스의 toString 메소드를 호출하는 것이다.
String str1 = "hi";
System.out.println(str1);
즉, 인스턴스 참조 값을 받아서 toString 메소드를 호출해서 출력하는 것이다.
- %g는 간단한 실수는 %f로 소수점이 길어지면 %e로 유연하게 출력해준다.
- Scanner
입출력할 때 활용되는 class
사용법:
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
String str1 = sc.nextLine();
...
- 엔터를 처리해주기 위해 중간에 sc.nextLine()을 적어줘야 할 때가 있다!