-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintfUsesInt.java
More file actions
35 lines (24 loc) · 949 Bytes
/
PrintfUsesInt.java
File metadata and controls
35 lines (24 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public class PrintfUsesInt {
public static void main(String[]args){
//%[flag][width][.precision][specifier-character]
//0 padding for same width
//number right justified padding(rempves zeroes gives spaces)
//-ve no. = left justified padding
int id1=1;
int id2=23;
int id3=456;
int id4=7898;
// System.out.printf("%04d\n",id1);//0001
// System.out.printf("%04d\n",id2);//0023
// System.out.printf("%04d\n",id3);//0456
// System.out.printf("%04d\n",id4);//7898
// System.out.printf("%4d\n",id1);// 1
// System.out.printf("%4d\n",id2);// 23
// System.out.printf("%4d\n",id3);// 456
// System.out.printf("%4d\n",id4);//7898
System.out.printf("%-4d\n",id1);//1
System.out.printf("%-4d\n",id2);//23
System.out.printf("%-4d\n",id3);//456
System.out.printf("%-4d\n",id4);//7898
}
}