0

Why we use %2d in array?

Can I know if there is any word to replace %2d? Or we must use %2d? public class Main { public static void main(String[] args) { int [][]a = new int[10][10]; for(int i = 0; i < 10; i++) { for(int j = 0; j < 10; j++) { System.out.printf("%2d ", a[i][j]); } System.out.println(); } } }

7th Jan 2023, 2:45 PM
Aenul
Aenul - avatar
4 Antworten
7th Jan 2023, 3:05 PM
SoloProg
SoloProg - avatar
+ 1
Meaning of %2d is it outputs a integer which fills (here 2) character spaces which also insert spaces to it's both side, if we increase the value the width will also increase. Ex:- %6d will fill six character spaces
8th Jan 2023, 5:22 AM
五条悟 ♡
五条悟 ♡ - avatar
+ 1
Ouhh, now i understand. Thanks for your help!!
8th Jan 2023, 6:23 AM
Aenul
Aenul - avatar
0
ainul mardhiah you are most welcome
8th Jan 2023, 6:30 AM
五条悟 ♡
五条悟 ♡ - avatar