Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package formatting.numbers;
- import java.util.Locale;
- import java.util.Scanner;
- public class FormattingNumbers {
- public static void main(String[] args) {
- Locale.setDefault(Locale.ROOT);
- Scanner input = new Scanner(System.in);
- int a = input.nextInt();
- while (a < 0 || a > 500) {
- System.out.println("Your input for \"a\" should be in the range 0 <= a <= 500: ");
- a = input.nextInt();
- }
- float b = input.nextFloat();
- float c = input.nextFloat();
- String aToHex = Integer.toHexString(a).toUpperCase();
- String aToBinary = String.format("%10s", Integer.toBinaryString(a)).replace(' ', '0');
- //printing
- System.out.printf("|%-10s|%s|%10.2f|%-10.3f|" ,aToHex,aToBinary,b,c);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement