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(); } } }
4 Respuestas
+ 4
How to format a Java int or long with printf example
https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/How-to-format-a-Java-int-with-printf-example
+ 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
+ 1
Ouhh, now i understand. Thanks for your help!!
0
ainul mardhiah you are most welcome