Answer to Question #67172 in Java | JSP | JSF for john ryan

Question #67172
Write a program that will accept an array of 10 integer (0-999) then prints a table the equivalent binary, octal
and hexadecimal.
1
Expert's answer
2017-04-05T10:43:07-0400
public class Main {

public static void main(String[] args) {
int[] arr = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};//example
converter(arr);
}

public static void converter(int[] arr) {
System.out.printf("%1$-11s %2$-11s %3$-11s %4$-11s", "Decimal", "Binary", "Octal", "Hexadecimal");
System.out.println();
for (int i = 0; i < arr.length; i++) {
System.out.printf("%1$-11s %2$-11s %3$-11s %4$-11s", arr[i] + "", Integer.toString(arr[i], 2), Integer.toString(arr[i], 8), Integer.toString(arr[i], 16));
System.out.println();
}
}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS