[코딩 오류 노트] if문, System, printf()/println(), 불필요한 .
1. printf 형식에 println 입력
오류 메시지
Exception in thread "main" java.lang.Error: Unresolved compilation problem: the method println(int) in the type PrintStream is not applicable for the arguments (String, int)
코드
System.out.println("음악을 %d번 재생했습니다.\n", ++count);
해결
(" ", )형식은 printf에서 사용한다.
printf(" ", )
println()
2. System.out.println에서 out 미입력
오류 메시지
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method println(String) is undefined for the type System
코드
System.println("반복 종료");
해결
System.out.println("반복 종료");
3. if문 조건식 미입력
오류 메시지
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error on token "(", Expression expected after this token
코드
if()
{
System.out.println("다시 입력해주세요.");
continue;
}
해결
if() 안에 조건식을 입력한다.
4. System을 system으로 입력
오류 메시지
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
system cannot be resolved to a variable
코드
sc = new Scanner(system.in);
해결
sc = new Scanner(System.in);
java는 대문자와 소문자를 구별한다.
Scanner와 String, System 등 대문자로 써야 하는 것에는 주의한다.
5. 불필요한 .
오류 메시지
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error on token ".", Identifier expected after this token
코드
Scanner sc;
sc = new Scanner.(System.in);
해결
new Scanner(System.in);