package orientedProgramming;
public class FanRunner {
public static void main(String[] args) {
Fan fan= new Fan("SAMSUNG", 1, "WHITE");
System.out.println(fan.toString());
}
}
package orientedProgramming;
public class Fan {
private String make;
private double radious;
private String color;
private boolean isOn;
private byte speed;
// 생성자
public Fan(String make, double radious, String color)
{
this.make = make;
this.radious = radious;
this.color = color;
}
public String toString()
{
return String.format("make : %s, radious : %f, color : %s, isOn : %b, speed : %d"
, make, radious, color, isOn, speed);
}
}
int i = 23;
System.out.println(String.format("%d_", i));
System.out.println(String.format("%5d_", i));
System.out.println(String.format("%-5d_", i));
System.out.println(String.format("%05d_", i));
----------------------------------------------
23_
23_
23 _
00023_
-----------------------------------------------
%5d 와 같이 %와 d 사이에 정수를 설정하면, 글자 길이를 설정할 수 있습니다.
기본적으로 오른쪽 정렬이고, -를 붙일 경우 왼쪽정렬입니다.(ln 4~5)
표현할 숫자인 i의 길이가 5보다 작을 경우 0을 붙입니다.(leading 0s) (ln 6)
% 바로 뒤에 , 를 붙이면 3자리 단위로 쉼표를 찍어줍니다.
출처: https://blog.jiniworld.me/68#a01 [hello jiniworld:티스토리]