Question: Problem 2 (50 pts). Write a Java program to convert a decimal number to its hexadecimal version. For example: Input: 123 Output: 7B The input
Problem 2 (50 pts). Write a Java program to convert a decimal number to its hexadecimal version. For example: Input: 123 Output: 7B The input is given as an int variable and the output should be a string. What to program: The skeleton of the program is given to you in Dec2Hex.java. Finish the program by yourself. What to submit: Dec2Hex.java that contains finished program.
import java.lang.*; import java.util.Scanner; public class Dec2Hex { // You are required to finish this function // Assume input string contains NO blank space or any none-letter character. public static String Convert(int num){ //Convert the input number into its hex representation. return ""; } public static void main(String[] args) { // Test your function here Scanner in = new Scanner(System.in); System.out.println("Let try a number..."); int num = in.nextInt(); String hex = Convert(num); System.out.println("The hex code of " + num + " is " + hex); } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
