println VS. printf
줄넘김 VS. 지시자
진수 | 설명 |
---|---|
2진수 | 없음 단, 10진수의 숫자-> 2진수의 문자열 바꿔주는 함수 존재 바로바로 "%s",Integer.toBinaryString(변수) |
10진의 정수 | %d |
8진수 | %o |
16진수 | %x %X |
지수 | %e %E |
부동 소수점 | %f (ex 123) %5f(ex□□123) %14.3 ( 14개의 자리 중 3개를 소수점으로 부여 123.1236 ->□□□□□□□□□□□□123.123 123.1->□□□□□□□□□□□□123.100 기본적으로 소수점 6자리까지만 출력, 7자리에서 반올림) %08f (123->00000123) %-8f (123->123□□□□□) |
문자 | %c |
문자열 | %s %20s(오른쪽부터 채워짐) %-20%(왼쪽부터 채워짐) %.8s(왼쪽에서 8글자만 출력) |
import java.util.*;
class ScannerEx{
public static void main(String[] args){
Scanner scanner = new Scanner (System.in);
System.out.printf("두자리 정수를 입력하시오>");
String input = scanner.nextLine();
int num = Integer.parseInt(input);
System.out.printf("입력내용:%s%n",input);
System.out.printf("num=%d%n",num);
}
}