Advertisement
M_Andreev

FormattingNumbers

Sep 7th, 2014
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _06_FormattingNumbers {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.         System.out.print("First number(0 <= a <= 500: ");
  7.         int num1 = sc.nextInt();
  8.        
  9.         System.out.print("Second number: ");
  10.         double num2 = sc.nextDouble();
  11.        
  12.         System.out.print("Third number: ");
  13.         double num3 = sc.nextDouble();
  14.        
  15.         String num1Hex = Integer.toHexString(num1).toUpperCase();
  16.         String num1Bin = String.format("%10s", Integer.toBinaryString(num1)).replace(" ", "0");
  17.        
  18.         System.out.printf("|%-10s|%s|%10.2f|%-10.3f|",num1Hex,num1Bin,num2,num3);
  19.     }
  20.    
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement