Menu Close

Conversion from Octal to hexadecimal in Java …ftc

Java Program to convert from octal to hexadecimal number.

Input:
Octal: 15

Output:
Hexadecimal: d
import java.io.*;
import java.util.*;
public class temp{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    System.out.print("Enter Octal number:  ");
    String octnum = scan.nextLine();

    int decnum = Integer.parseInt(octnum,8);
    String hexanum = Integer.toHexString(decnum).toUpperCase();

    System.out.println("Hexadecimal number is:  "+hexanum);
	}
}

INPUT_1:
Enter Octal number:  10453

OUTPUT:
Hexadecimal number is:  112B


INPUT_2:
Enter Octal number:  10452

OUTPUT:
Hexadecimal number is:  112A


INPUT_3:
Enter Octal number:  15

OUTPUT:
Hexadecimal number is:  D


INPUT_4:
Enter Octal number:  25

OUTPUT:
Hexadecimal number is:  15


INPUT_5:
Enter Octal number:  1023

OUTPUT:
Hexadecimal number is:   213


INPUT_6:
Enter Octal number:  500

OUTPUT:
Hexadecimal number is:  140


INPUT_7:
Enter Octal number:  510

OUTPUT:
Hexadecimal number is:  148


INPUT_8:
Enter Octal number:  10450

OUTPUT:
Hexadecimal number is:  1128


ILLUSTRATION

Executed using javac on ubuntu terminal