Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Java Examples

Java Code Examples and sample source code.
Andr's picture

Convert Hexadecimal to decimal example

0
Your rating: None
  1. /*
  2.  * Convert Hexadecimal to decimal example. Program to convert Hexadecimal number
  3.  * to decimal number.
  4.  */
  5.  
  6. public class HexToDecimal {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   String strHexNumber = "8";
  11.  
  12.   /*
  13.    * To convert Hexadecimal to decimal number, use
  14.    * parseInt method of Integer wrapper.
  15.    *
  16.    * In this case, radix would be 16
  17.    */
  18.  
Andr's picture

Convert Decimal to Octal example

2
Your rating: None Average: 2 (4 votes)
  1. /*
  2.  * Convert Decimal to Octal example. Program to convert decimal number
  3.  * to octal number.
  4.  */
  5.  
  6. public class DecimalToOctal {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   int decimalNumber = 56;
  11.  
  12.   /*
  13.    * To convert decimal to octal number, use
  14.    * toOctalString method of Integer wrapper.
  15.    */
  16.  
  17.   String strOctalNumber = Integer.toOctalString(decimalNumber);
Andr's picture

Convert Decimal to Hexadecimal example

0
Your rating: None
  1. /*
  2.  * Convert Decimal to Hexadecimal example. Program to convert decimal number
  3.  * to Hexadecimal number.
  4.  */
  5.  
  6. public class DecimalToHex {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   int decimalNumber = 17;
  11.  
  12.   /*
  13.    * To convert decimal to hexadecimal number, use
  14.    * toHexString method of Integer wrapper.
  15.    */
  16.  
Andr's picture

Convert Decimal to Binary example

2
Your rating: None Average: 2 (4 votes)
  1. /*
  2.  * Convert Decimal to Binary example. Program to convert decimal number
  3.  * to binary number.
  4.  */
  5.  
  6. public class DecimalToBinary {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   //string having decimal number
  11.   String decimalString = new String("21");
  12.  
  13.   /*
  14.    * To convert decimal number to binary number use
  15.    * static parseInt method of Integer wrapper class.
Andr's picture

Convert Binary to Decimal example

5
Your rating: None Average: 5 (1 vote)
  1. /*
  2.  * Convert Binary to Decimal example. Program to convert binary number
  3.  * to decimal number.
  4.  */
  5.  
  6. public class BinaryToDecimal {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   //string having binary number
  11.   String binaryString = new String("10101");
  12.  
  13.   /*
  14.    * To convert binary number to decimal number use
  15.    * static parseInt method of Integer wrapper class.
Rahimv's picture

Convert String to Integer example

1
Your rating: None Average: 1 (1 vote)
  1. /*
  2.  * Convert String to Integer example. Program to convert Java
  3.  * String object to Integer object.
  4.  */
  5.  
  6. public class StringToInteger {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   //new String object
  11.   String str = new String("47");
  12.  
  13.   //Use Integer(String) constructor
  14.   Integer iObj1 = new Integer(str);
  15.  
Rahimv's picture

Convert String to primitive int example

5
Your rating: None Average: 5 (1 vote)
  1. /*
  2.  * Convert String to primitive int example. Program to convert Java
  3.  * String object to primitive int data type.
  4.  */
  5.  
  6. public class StringToInt {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   //new String object
  11.   String str = new String("342");
  12.  
  13.   /*
  14.    * To convert String to primitive int data type, use
  15.    * parseInt(String) static method of Integer class
Rahimv's picture

Convert Integer to String example

0
Your rating: None
  1. /*
  2.  * Convert Integer to String example. Program to convert Java
  3.  * Integer object to String object.
  4.  */
  5.  
  6. public class IntegerToString {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   //new Integer object
  11.   Integer iObj = new Integer("12");
  12.  
  13.   //to convert Integer to String use toString method of Integer wrapper class
  14.   String strBValue = iObj.toString();
  15.  
Rahimv's picture

Convert Integer to primitive int example

2
Your rating: None Average: 2 (2 votes)
  1. /*
  2.  * Convert Integer to primitive int example.
Rahimv's picture

Convert String to primitive double example

0
Your rating: None
  1. /*
  2.  * Convert String to primitive double example. Program to convert Java
  3.  * String object to primitive double data type.
  4.  */
  5.  
  6. public class StringToPrimitiveDouble {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   //new String object
  11.   String str = new String("43.21");
  12.  
  13.   /*
  14.    * To convert String to primitive double data type, use
Syndicate content