doublemetal 2013. 7. 16. 23:19



public class StringFormatTest {


public static void main(String[] args) {

// TODO Auto-generated method stub


String str;

str = String.format("%d", 20); 

System.out.println("str = "+str);

//str의 값 세팅, 20의 값을 가진 정수로 출력

str = String.format("%10d", 40);

System.out.println("str = "+str);

//다시 정수형으로 세팅, 10칸의 공간에 오른쪽 정렬

//비슷한 기능으로 System.printf() 메소드가 있다. 

//-> C언어의 printf()와 동일

}

}



str = 20
str =         40