Advertisement
n_stefanov

Ex6_FormattingNumbers

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