Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import java.text.NumberFormat;
- /**
- Modify this program to produce right-justified columns, like this:
- 23 5 213 9 325
- 4 123 23 35 3
- 879 21 8 223 98
- */
- public class FormatNumber
- {
- public static void main(String[] args)
- {
- int[][] numbers = { {23, 5, 213, 9, 325},
- {4, 123, 23, 35, 3},
- {879, 21, 8, 223, 98}
- };
- NumberFormat formatter;
- String pattern = "###";
- for (int row = 0; row < 3; row++)
- {
- for (int col = 0; col < 5; col++)
- {
- formatter = new DecimalFormat(pattern);
- String number = formatter.format(numbers[row][col]);
- System.out.print(number + " ");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment