Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.Format;
- import java.util.Scanner;
- public class FormatingNumbers {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- double a = input.nextDouble();
- double b = input.nextDouble();
- double c = input.nextDouble();
- System.out.print("|" + convertHex(254));
- System.out.print("|" + convertBin(254));
- System.out.printf("%10.2f|%-10.0f", b, c);
- }
- public static String convertHex(int n) {
- String converted = Integer.toHexString(n);
- int difference = 10 - converted.length();
- String current = converted;
- for (int i = 0; i < difference; i++) {
- current += " ";
- }
- return current;
- }
- public static String convertBin(int n) {
- String converted = Integer.toBinaryString(n);
- int difference = 10 - converted.length();
- String current = "";
- for (int i = 0; i < difference; i++) {
- current += "0";
- }
- current += converted;
- return current;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement