Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*6.Write a program that reads 3 numbers: an integer a (0 ≤ a ≤ 500), a floating-point
- b and a floating-point c and prints them in 4 virtual columns on the console.
- Each column should have a width of 10 characters. The number a should be printed
- in hexadecimal, left aligned; then the number a should be printed in binary form,
- padded with zeroes, then the number b should be printed with 2 digits after the
- decimal point, right aligned; the number c should be printed with 3 digits after
- the decimal point, left aligned.*/
- import java.util.Scanner;
- public class FormattingNumbers {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println("Enter a positive integer number!");
- int num =input.nextInt();
- System.out.println("Enter a float number!");
- float numF1 = input.nextFloat();
- System.out.println("Enter a float number!");
- float numF2 = input.nextFloat();
- String hexNum = Integer.toHexString(num);
- String binNum = Integer.toBinaryString(num);
- System.out.format("|%-10s|%010d|%10.2f|%-10.3f|", hexNum, Integer.parseInt(binNum),numF1,numF2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement