Showing posts with label decimal to hexadecimal in java. Show all posts
Showing posts with label decimal to hexadecimal in java. Show all posts

Friday, September 29, 2017

Decimal To Hexadecimal Converter in Java

A very simple program to ask the user to give a value in integer or decimal and then convert it into hexadecimal equivalent using Java as our programming language. The code is very easy to understand and use.

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing


Decimal_Hexa.java


import java.util.Scanner;

/**
 * @author Jake R. Pomperada
 * Bacolod City, Negros Occidental, Philippines
 * September 29, 2017  Friday    7:42 PM
*/


public class Decimal_Hexa {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int deci_values, rem, orig;
                String hexdecnum_values="";
        
Scanner input = new Scanner(System.in);
        
        char hexa_values[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
        
        System.out.print("\n\n");
System.out.print("===== Decimal To Hexadecimal Converter in Java ====");
System.out.print("\n\n");
System.out.print("===== Written By: Mr. Jake R. Pomperada =====");;
System.out.print("\n\n");
       
        System.out.print("Give Decimal Number : ");
        deci_values = input.nextInt();
        orig = deci_values;
        
        while(deci_values >0)
        {
            rem = deci_values % 16;
            hexdecnum_values = hexa_values[rem] + hexdecnum_values;
            deci_values /=16;
        }
        System.out.println();
        System.out.print("The Equivalent Hexadecimal Value of " + orig + " is ");
        System.out.print(hexdecnum_values + ".");
        System.out.print("\n\n");
System.out.println("END OF PROGRAM");
 System.out.println();
        input.close();

}

}