AlexKondov

Java Formatting Numbers

May 13th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class FormattingNumbers {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.         int a = input.nextInt();
  9.         double b = input.nextDouble();
  10.         double c = input.nextDouble();
  11.        
  12.         String aHexadecimal = Integer.toHexString(a);
  13.         String aBinary = String.format("%10s", Integer.toBinaryString(a)).replace(' ', '0');
  14.        
  15.         if (c%1 == 0) {
  16.             System.out.printf("|%-10s|%s|%10.2f|%-10.0f|",aHexadecimal,aBinary,b,c);
  17.         }
  18.         else {
  19.             System.out.printf("|%-10s|%s|%10.2f|%-10.3f|",aHexadecimal,aBinary,b,c);
  20.         }
  21.     }
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment