Advertisement
Asenov

Formatting Numbers

Mar 17th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FormattingNumbers {
  4.     public static void main(String[] args) {
  5.         Scanner input = new Scanner(System.in);
  6.         int a = input.nextInt();
  7.         double b = input.nextDouble();
  8.         double c = input.nextDouble();
  9.         String aHex = Integer.toHexString(a).toUpperCase();
  10.         String aBin = String.format("%10s", Integer.toBinaryString(a)).replace(" ", "0");
  11.  
  12.         System.out.format("|%-10s|%s|%10.2f|%-10.3f|" , aHex, aBin, b, c);
  13.     }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement