Q:

Write a Java program to convert a octal number to a hexadecimal number

0

Write a Java program to convert a octal number to a hexadecimal number
Input Data:
Input a octal number : 100
Expected Output:

Equivalent hexadecimal number: 40

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;

public class Exercise27 {
public static void main(String args[])
    {
        String octal_num, hex_num;
        int decnum;
        Scanner in = new Scanner(System.in);
		
        System.out.print("Input a octal number : ");
        octal_num = in.nextLine();
		
        decnum = Integer.parseInt(octal_num, 8);
        hex_num = Integer.toHexString(decnum);
		
        System.out.print("Equivalent hexadecimal number: "+ hex_num+"\n");
     }
}

Sample Output:

Input a octal number : 100                                                                                    
Equivalent hexadecimal number: 40

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now