Java Code Examples and sample source code.
|
|
Submitted by Andr on Sat, 08/28/2010 - 23:06
/*
* Convert Hexadecimal to decimal example. Program to convert Hexadecimal number
* to decimal number.
*/
public class HexToDecimal {
public static void main(String args[]){
String strHexNumber = "8";
/*
* To convert Hexadecimal to decimal number, use
* parseInt method of Integer wrapper.
*
* In this case, radix would be 16
*/
|
|
|
Submitted by Andr on Sat, 08/28/2010 - 23:05
/*
* Convert Decimal to Octal example. Program to convert decimal number
* to octal number.
*/
public class DecimalToOctal {
public static void main(String args[]){
int decimalNumber = 56;
/*
* To convert decimal to octal number, use
* toOctalString method of Integer wrapper.
*/
String strOctalNumber = Integer.toOctalString(decimalNumber);
|
|
|
Submitted by Andr on Sat, 08/28/2010 - 23:04
/*
* Convert Decimal to Hexadecimal example. Program to convert decimal number
* to Hexadecimal number.
*/
public class DecimalToHex {
public static void main(String args[]){
int decimalNumber = 17;
/*
* To convert decimal to hexadecimal number, use
* toHexString method of Integer wrapper.
*/
|
|
|
Submitted by Andr on Sat, 08/28/2010 - 23:04
/*
* Convert Decimal to Binary example. Program to convert decimal number
* to binary number.
*/
public class DecimalToBinary {
public static void main(String args[]){
//string having decimal number
String decimalString = new String("21");
/*
* To convert decimal number to binary number use
* static parseInt method of Integer wrapper class.
|
|
|
Submitted by Andr on Sat, 08/28/2010 - 23:02
/*
* Convert Binary to Decimal example. Program to convert binary number
* to decimal number.
*/
public class BinaryToDecimal {
public static void main(String args[]){
//string having binary number
String binaryString = new String("10101");
/*
* To convert binary number to decimal number use
* static parseInt method of Integer wrapper class.
|
|
|
Submitted by Rahimv on Sat, 08/28/2010 - 22:57
/*
* Convert String to Integer example. Program to convert Java
* String object to Integer object.
*/
public class StringToInteger {
public static void main(String args[]){
//new String object
String str = new String("47");
//Use Integer(String) constructor
Integer iObj1 = new Integer(str);
|
|
|
Submitted by Rahimv on Sat, 08/28/2010 - 22:56
/*
* Convert String to primitive int example. Program to convert Java
* String object to primitive int data type.
*/
public class StringToInt {
public static void main(String args[]){
//new String object
String str = new String("342");
/*
* To convert String to primitive int data type, use
* parseInt(String) static method of Integer class
|
|
|
Submitted by Rahimv on Sat, 08/28/2010 - 22:55
/*
* Convert Integer to String example. Program to convert Java
* Integer object to String object.
*/
public class IntegerToString {
public static void main(String args[]){
//new Integer object
Integer iObj = new Integer("12");
//to convert Integer to String use toString method of Integer wrapper class
String strBValue = iObj.toString();
|
|
|
Submitted by Rahimv on Sat, 08/28/2010 - 22:54
/*
* Convert Integer to primitive int example.
|
|
|
Submitted by Rahimv on Sat, 08/28/2010 - 22:50
/*
* Convert String to primitive double example. Program to convert Java
* String object to primitive double data type.
*/
public class StringToPrimitiveDouble {
public static void main(String args[]){
//new String object
String str = new String("43.21");
/*
* To convert String to primitive double data type, use
|
|