Advertisement
Guest User

Problem 6. Formatting Numbers

a guest
May 15th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 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. //Enter number
  9. System.out.print("Enter int a: ");
  10. int a = input.nextInt();
  11. System.out.print("Enter int b: ");
  12. float b = input.nextFloat();
  13. System.out.print("Enter int c: ");
  14. float c = input.nextFloat();
  15.  
  16. //Calculate hex and bin
  17. String Ahex = Integer.toHexString(a);
  18. String Abin = Integer.toBinaryString(a);
  19. int A = Integer.parseInt(Abin);
  20.  
  21. //Print
  22. System.out.printf("|%-10s|", Ahex);
  23. System.out.printf("%010d|", A);
  24. System.out.printf("%10.2f|", b);
  25. System.out.printf("%-10.3f|", c);
  26.  
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement