Advertisement
veronikaaa86

formatting number

Nov 17th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1.  
  2. import java.math.BigDecimal;
  3. import java.util.Scanner;
  4.  
  5. public class P03_FormattingNumber {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int a = Integer.parseInt(scanner.next());
  10.         double b = Double.parseDouble(scanner.next());
  11.         double c = Double.parseDouble(scanner.next());
  12.  
  13.         String hex = Integer.toHexString(a).toUpperCase();
  14.         String bin = String.format("%010d", Integer.parseInt(Integer.toBinaryString(a)));
  15.  
  16.         System.out.printf("|%-10s|%s|%10.2f|%-10.3f|", hex, bin, b, c);
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement