Created
July 18, 2022 14:40
-
-
Save ManduTheCat/8a6d9621a7cbc1d4900b80d068b93bbe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DigitTest2 { | |
public static void main(String[] args) { | |
int[][] nums = new int[][]{{1,2,3,4,5},{6,7,8},{9},{10,11,12},{13,14,15,16,17}}; | |
int maxLen = 0; | |
// 기준이 되는 최대 길이를 찾는다. | |
for (int[] ints : nums) { | |
if (maxLen < ints.length) { | |
maxLen = ints.length; | |
} | |
} | |
// 모래시계 출력 | |
for (int[] num : nums) { | |
int len = num.length; | |
for (int b = 0; b < maxLen - len; b++) { | |
System.out.print(" "); | |
} | |
for (int i : num) { | |
if (i < 10) { | |
System.out.printf("%2d", i); | |
} else { | |
System.out.print(i + " "); | |
} | |
} | |
for (int b1 = 0; b1 < maxLen - len; b1++) { | |
System.out.print(" "); | |
} | |
System.out.println(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment