Advertisement
wulev

Formatting Numbers Output

May 30th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. package formatting.numbers;
  2.  
  3. import java.util.Locale;
  4. import java.util.Scanner;
  5.  
  6. public class FormattingNumbers {
  7.  
  8.     public static void main(String[] args) {
  9.         Locale.setDefault(Locale.ROOT);
  10.        
  11.         Scanner input = new Scanner(System.in);
  12.         int a = input.nextInt();
  13.        
  14.         while (a < 0 || a > 500) {
  15.             System.out.println("Your input for \"a\" should be in the range 0 <= a <= 500: ");
  16.             a = input.nextInt();
  17.         }
  18.        
  19.         float b = input.nextFloat();
  20.         float c = input.nextFloat();
  21.         String aToHex = Integer.toHexString(a).toUpperCase();
  22.         String aToBinary = String.format("%10s", Integer.toBinaryString(a)).replace(' ', '0');
  23.        
  24.         //printing
  25.         System.out.printf("|%-10s|%s|%10.2f|%-10.3f|" ,aToHex,aToBinary,b,c);
  26.     }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement