0% found this document useful (0 votes)
52 views32 pages

Java Data Type Conversion Guide

The document discusses various ways to convert between Java data types like String, int, long, and Date. It provides examples and explanations of commonly used methods like Integer.parseInt(), String.valueOf(), SimpleDateFormat.parse() for converting between these types in Java. Key points covered include converting String to int, long, Date and vice versa using methods from classes like Integer, Long, DateFormat, SimpleDateFormat.

Uploaded by

coyol91896
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views32 pages

Java Data Type Conversion Guide

The document discusses various ways to convert between Java data types like String, int, long, and Date. It provides examples and explanations of commonly used methods like Integer.parseInt(), String.valueOf(), SimpleDateFormat.parse() for converting between these types in Java. Key points covered include converting String to int, long, Date and vice versa using methods from classes like Integer, Long, DateFormat, SimpleDateFormat.

Uploaded by

coyol91896
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Chapter 2: Java Conversion

Java Convert String to int


convert String to an int in java using [Link]() method. To convert String into
Integer, we can use [Link]() method which returns instance of Integer class.

It is used to perform mathematical operations on the string which contains a number.


Whenever we receive data from TextField or TextArea, entered data is received as a
string. If entered data is in number format, we need to convert the string to an int. To do
so, we use [Link]() method.

Signature

The parseInt() is the static method of Integer class. The signature of parseInt() method is given
below:

1. public static int parseInt(String s)

Java String to int Example: [Link]()

int i=[Link]("200");

Let's see the simple example of converting String to int in Java.

//Java Program to demonstrate the conversion of String into int


//using [Link]() method
public class StringToIntExample1{
public static void main(String args[]){
//Declaring String variable
String s="200";
//Converting String into int using [Link]()
int i=[Link](s);
//Printing value of i
[Link](i);
}}
Output:

200

Understanding String Concatenation Operator

//Java Program to understand the working of string concatenation operator


public class StringToIntExample{
public static void main(String args[]){
//Declaring String variable
String s="200";
//Converting String into int using [Link]()
int i=[Link](s);
[Link](s+100);//200100, because "200"+100, here + is a string concatenation operator
[Link](i+100);//300, because 200+100, here + is a binary plus operator
}}

1. Output:

2. 200100
3. 300

 Java Convert int to String


We can convert int to String in java using [Link]() and [Link]() methods.
Alternatively, we can use [Link]() method, string concatenation operator etc.

1) [Link]()

The [Link]() method converts int to String. The valueOf() is the static method of String
class. The signature of valueOf() method is given below:

1. public static String valueOf(int i)

Java int to String Example using [Link]()

Let's see the simple code to convert int to String in java.


int i=10;
String s=[Link](i);//Now it will return "10"

Let's see the simple example of converting String to int in java.

public class IntToStringExample1{


public static void main(String args[]){
int i=200;
String s=[Link](i);
[Link](i+100);//300 because + is binary plus operator
[Link](s+100);//200100 because + is string concatenation operator
}}

Output:

300
200100

2) [Link]()

The [Link]() method converts int to String. The toString() is the static method of
Integer class. The signature of toString() method is given below:

public static String toString(int i)

Java int to String Example using [Link]()

Let's see the simple code to convert int to String in java using [Link]() method.

int i=10;
String s=[Link](i);//Now it will return "10"

Let's see the simple example of converting String to int in java.

public class IntToStringExample2{


public static void main(String args[]){
int i=200;
String s=[Link](i);
[Link](i+100);//300 because + is binary plus operator
[Link](s+100);//200100 because + is string concatenation operator
}}

Output:

300
200100

3) [Link]()

The [Link]() method is used to format given arguments into String. It is introduced since
Jdk 1.5.

1. public static String format(String format, Object... args)

Java int to String Example using [Link]()


public class IntToStringExample3{
public static void main(String args[]){
int i=200;
String s=[Link]("%d",i);
[Link](s);
}}

Output:

200
 Java String to long
We can convert String to long in java using [Link]() method.

Signature

The parseLong() is the static method of Long class. The signature of parseLong() method is
given below:

1. public static long parseLong(String s)

Java String to long Example


long l=[Link]("200");
public class StringToLongExample
{
public static void main(String args[])
{
String s="9990449935";
long l=[Link](s);
[Link](l);
}}

Output:

9990449935

 Java long to String

We can convert long to String in java using [Link]() and [Link]() methods.

It is used if we have to display long number in textfield in GUI application because everything is
displayed as a string in form.
1) [Link]()

The [Link]() is an overloaded method. It can be used to convert long to String. The
valueOf() is the static method of String class. The signature of valueOf() method is given below:

1. public static String valueOf(long i)

Java long to String Example using [Link]()


long i=9993939399L;//L is the suffix for long
String s=[Link](i);//Now it will return "9993939399"

public class LongToStringExample1


{
public static void main(String args[])
{
long i=9993939399L;
String s=[Link](i);
[Link](s);
}}

Output:

9993939399

2) [Link]()

The [Link]() method converts long to String. The toString() is the static method of Long
class. The signature of toString() method is given below:

1. public static String toString(long i)

Java long to String Example using [Link]()


long i=9993939399L;
String s=[Link](i);//Now it will return "9993939399"

public class LongToStringExample2{


public static void main(String args[]){
long i=9993939399L;
String s=[Link](i);
[Link](s);
}}

Output:

9993939399

Java String to Date

We can convert String to Date in java using parse() method of DateFormat and
SimpleDateFormat classes.

java String to Date Example

import [Link];
import [Link];
public class StringToDateExample1 {
public static void main(String[] args)throws Exception {
String sDate1="31/12/1998";
Date date1=new SimpleDateFormat("dd/MM/yyyy").parse(sDate1);
[Link](sDate1+"\t"+date1);
}
}

Output:

31/12/1998 Thu Dec 31 [Link] IST 1998


import [Link];
import [Link];
public class StringToDateExample2 {
public static void main(String[] args)throws Exception {
String sDate1="31/12/1998";
String sDate2 = "31-Dec-1998";
String sDate3 = "12 31, 1998";
String sDate4 = "Thu, Dec 31 1998";
String sDate5 = "Thu, Dec 31 1998 [Link]";
String sDate6 = "31-Dec-1998 [Link]";
SimpleDateFormat formatter1=new SimpleDateFormat("dd/MM/yyyy");
SimpleDateFormat formatter2=new SimpleDateFormat("dd-MMM-yyyy");
SimpleDateFormat formatter3=new SimpleDateFormat("MM dd, yyyy");
SimpleDateFormat formatter4=new SimpleDateFormat("E, MMM dd yyyy");
SimpleDateFormat formatter5=new SimpleDateFormat("E, MMM dd yyyy HH:mm:ss");
SimpleDateFormat formatter6=new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
Date date1=[Link](sDate1);
Date date2=[Link](sDate2);
Date date3=[Link](sDate3);
Date date4=[Link](sDate4);
Date date5=[Link](sDate5);
Date date6=[Link](sDate6);
[Link](sDate1+"\t"+date1);
[Link](sDate2+"\t"+date2);
[Link](sDate3+"\t"+date3);
[Link](sDate4+"\t"+date4);
[Link](sDate5+"\t"+date5);
[Link](sDate6+"\t"+date6);
}
}

Output:
31/12/1998 Thu Dec 31 [Link] IST 1998
31-Dec-1998 Thu Dec 31 [Link] IST 1998
12 31, 1998 Thu Dec 31 [Link] IST 1998
Thu, Dec 31 1998 Thu Dec 31 [Link] IST 1998
Thu, Dec 31 1998 [Link] Thu Dec 31 [Link] IST 1998
31-Dec-1998 [Link] Thu Dec 31 [Link] IST 1998

 Java Convert Date to String

convert Date to String in java using format() method of [Link] class.

format() method of DateFormat

The format() method of DateFormat class is used to convert Date into String. DateFormat is
an abstract class. The child class of DateFormat is SimpleDateFormat. It is the
implementation of DateFormat class. The signature of format() method is given below:

String format(Date d)

Java Date to String Example

Let's see the simple code to convert Date to String in java.

Date date = [Link]().getTime();


DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
String strDate = [Link](date);

Example:596Java Try Catch

import [Link];
import [Link];
import [Link];
import [Link];
public class DateToStringExample1 {
public static void main(String args[])
{
Date date = [Link]().getTime();
DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
String strDate = [Link](date);
[Link]("Converted String: " + strDate);

}
}

Output:

Converted String: 2017-24-28 [Link]


import [Link];
import [Link];
import [Link];
import [Link];
public class DateToStringExample2 {
public static void main(String[] args) {
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
String strDate = [Link](date);
[Link]("Date Format with MM/dd/yyyy : "+strDate);

formatter = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");


strDate = [Link](date);
[Link]("Date Format with dd-M-yyyy hh:mm:ss : "+strDate);

formatter = new SimpleDateFormat("dd MMMM yyyy");


strDate = [Link](date);
[Link]("Date Format with dd MMMM yyyy : "+strDate);

formatter = new SimpleDateFormat("dd MMMM yyyy zzzz");


strDate = [Link](date);
[Link]("Date Format with dd MMMM yyyy zzzz : "+strDate);
formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z");
strDate = [Link](date);
[Link]("Date Format with E, dd MMM yyyy HH:mm:ss z : "+strDate);
}
}

Output:

Date Format with MM/dd/yyyy : 04/13/2015


Date Format with dd-M-yyyy hh:mm:ss : 13-4-2015 [Link]
Date Format with dd MMMM yyyy : 13 April 2015
Date Format with dd MMMM yyyy zzzz : 13 April 2015 India Standard Time
Date Format with E, dd MMM yyyy HH:mm:ss z : Mon, 13 Apr 2015 [Link] IST

 Java Convert String to char

convert String to char in java using charAt() method of String class.

The charAt() method returns a single character only. To get all characters, you can use loop.

Signature

The charAt() method returns a single character of specified index. The signature of charAt()
method is given below:

1. public char charAt(int index)

Java String to char Example: charAt() method


String s="hello";
char c=[Link](2);//returns l

Let's see the simple example of converting String to char in java.

public class StringToCharExample1{


public static void main(String args[]){
String s="hello";
char c=[Link](0);//returns h
[Link]("1st character is: "+c);
}}

Output:

1st character is: h


public class StringToCharExample2{
public static void main(String args[]){
String s="hello";
for(int i=0; i<[Link]();i++){
char c = [Link](i);
[Link]("char at "+i+" index is: "+c);
}
}}

Output:

char at 0 index is: h


char at 1 index is: e
char at 2 index is: l
char at 3 index is: l
char at 4 index is: o

Java String to char Example: toCharArray() method

public class StringToCharExample3{


public static void main(String args[]){
String s1="hello";
char[] ch=[Link]();
for(int i=0;i<[Link];i++){
[Link]("char at "+i+" index is: "+ch[i]);
}
}}

Output:

char at 0 index is: h


char at 1 index is: e
char at 2 index is: l
char at 3 index is: l
char at 4 index is: o

Java String to char Example: toCharArray() method

public class StringToCharExample3{


public static void main(String args[]){
String s1="hello";
char[] ch=[Link]();
for(int i=0;i<[Link];i++){
[Link]("char at "+i+" index is: "+ch[i]);
}
}}

Output:

char at 0 index is: h


char at 1 index is: e
char at 2 index is: l
char at 3 index is: l
char at 4 index is: o
 Java Convert char to String

We can convert char to String in java using [Link](char) method of String class
and [Link](char) method of Character class.

Java char to String Example: [Link]() method

char c='S';

String s=[Link](c);
public class CharToStringExample1{
public static void main(String args[]){
char c='S';
String s=[Link](c);
[Link]("String is: "+s);
}}

Output:.

String is: S

Java char to String Example: [Link]() method


public class CharToStringExample2{
public static void main(String args[]){
char c='M';
String s=[Link](c);
[Link]("String is: "+s);
}}

 Output:

String is: M

 Java Convert String to Object

We can convert String to Object in java with assignment operator. Each class is internally a
child class of Object class. So you can assign string to Object directly.

You can also convert String to Class type object using [Link]() method.

Java String to Object Example

String s="hello";
Object obj=s;

public class StringToObjectExample{


public static void main(String args[]){
String s="hello";
Object obj=s;
[Link](obj);
}}

Output:

hello

 Java String to Class object Example

code to convert String to Class object in java using [Link]() method. The
[Link]() method returns the instance of Class class which can be used to get the
metadata of any class.

public class StringToObjectExample2{


public static void main(String args[])throws Exception{
Class c=[Link]("[Link]");
[Link]("class name: "+[Link]());
[Link]("super class name: "+[Link]().getName());
}}

Output:

Class name: [Link]


Super class name: [Link]

 Java Convert Object to String

We can convert Object to String in java using toString() method of Object class or
[Link](object) method.

convert any object to String in java whether it is user-defined class, StringBuilder, StringBuffer
or anything else.
Here, we are going to see two examples of converting Object into String. In the first example, we
are going to convert Emp class object into String which is an user-defined class. In second
example, we are going to convert StringBuilder to String.

Java Object to String Example: Converting User-defined class


class Emp{}
public class ObjectToStringExample{
public static void main(String args[]){
Emp e=new Emp();
String s=[Link]();
String s2=[Link](e);
[Link](s);
[Link](s2);
}}

Output:

Emp@2a139a55
Emp@2a139a55

Java Object to String Example: Converting StringBuilder

code to convert StringBuilder object to String in java.

public class ObjectToStringExample2{


public static void main(String args[]){
String s="hello";
StringBuilder sb=new StringBuilder(s);
[Link]();
String rev=[Link]();//converting StringBuilder to String
[Link]("String is: "+s);
[Link]("Reverse String is: "+rev);
}}

Output:

String is: hello


Reverse String is: olleh

So, you can convert any Object to String in java using toString() or [Link](object)
methods.
 Java Convert int to long
We can convert int to long in java using assignment operator. There is nothing to do
extra because lower type can be converted to higher type implicitly.

It is also known as implicit type casting or type promotion.

Java int to long Example


public class IntToLongExample1
{
public static void main(String args[])
{
int i=200;
long l=i;
[Link](l);
}}

Output:

200

Java int to Long Example

We can convert int value to Long object by instantiating Long class or calling [Link]()
method.

public class IntToLongExample2{


public static void main(String args[]){
int i=100;
Long l= new Long(i);//first way
Long l2=[Link](i);//second way
[Link](l);
[Link](l2);
}}

Output:

100
100

 Java Convert long to int

We can convert long to int in java using typecasting. To convert higher data type into lower, we
need to perform typecasting.

Typecasting in java is performed through typecast operator (datatype).

Here, we are going to learn how to convert long primitive type into int and Long object into int.

Java long to int Example


public class LongToIntExample1{
public static void main(String args[]){
long l=500;
int i=(int)l;
[Link](i);
}}

Output:

500

Java Long to int Example

We can convert Long object to int by intValue() method of Long class.


public class LongToIntExample2{

public static void main(String args[]){


Long l= new Long(10);
int i=[Link]();
[Link](i);
}}

Output:

10

 Java Convert char to int

We can convert char to int in java using various ways. If we direct assign char variable to int, it
will return ASCII value of given character.

If char variable contains int value, we can get the int value by
calling [Link](char) method. Alternatively, we can use
[Link](char) method.

1) Java char to int Example: Get ASCII value


public class CharToIntExample1{
public static void main(String args[]){
char c='a';
char c2='1';
int a=c;
int b=c2;
[Link](a);
[Link](b);
}}

Output:

97
49

2) Java char to int Example: [Link]()

code to convert char to int in java using [Link](char) method which returns
an integer value.

public class CharToIntExample2{


public static void main(String args[]){
char c='1';
int a=[Link](c);
[Link](a);
}}

Output:

3) Java char to int Example: [Link]()

another example which returns integer value of specified char value using [Link](char)
method.

public class CharToIntExample3{


public static void main(String args[]){
char c='1';
int a=[Link]([Link](c));
[Link](a);
}}
Output:

 Java Convert int to char

convert int to char in java using typecasting. To convert higher data type into lower, we need to
perform typecasting. Here, the ASCII character of integer value will be stored in the char
variable.

To get the actual value in char variable, you can add '0' with int variable. Alternatively, you can
use [Link]() method.

Java int to char Example: Typecasting

public class IntToCharExample1{


public static void main(String args[]){
int a=65;
char c=(char)a;
[Link](a);
}}

Output:

But if you store 1, it will store ASCII character of given number which is start of heading which
is not printable. So it will not print anything on the console.
public class IntToCharExample2{
public static void main(String args[]){
int a=1;
char c=(char)a;
[Link](c);
}}

Output:

If you add '0' with int variable, it will return actual value in the char variable. The ASCII value of
'0' is 48. So, if you add 1 with 48, it becomes 49 which is equal to 1. The ASCII character of 49
is 1.

public class IntToCharExample3{


public static void main(String args[]){
int a=1;
char c=(char)(a+'0');
[Link](c);
}}

Output:

If you store integer value in a single quote, it will store actual character in char variable.

public class IntToCharExample4{


public static void main(String args[]){
int a='1';
char c=(char)a;
[Link](c);
}}

Output:

1
Java int to char Example: [Link]()

To get the actual value, you can also use [Link]() method.

public class IntToCharExample5{


public static void main(String args[]){
int REDIX=10;//redix 10 is for decimal number, for hexa use redix 16
int a=1;
char c=[Link](a,REDIX);
[Link](c);
}}

 Java Convert String to boolean

convert String to boolean in java using [Link](string) method.

To convert String into Boolean object, we can use [Link](string) method which returns
instance of Boolean class.

To get boolean true, string must contain "true". Here, case is ignored. So, "true" or "TRUE" will
return boolean true. Any other string value except "true" returns boolean false.

Java String to boolean Example: [Link]()

The parseBoolean() method converts string into boolean primitive.

The parseBoolean() is the static method of Boolean class. The signature of parseBoolean()
method is given below:

1. public static int parseBoolean(String s)

public class StringToBooleanExample{


public static void main(String args[]){
String s1="true";
String s2="TRue";
String s3="ok";
boolean b1=[Link](s1);
boolean b2=[Link](s2);
boolean b3=[Link](s3);
[Link](b1);
[Link](b2);
[Link](b3);
}}

Output:

true
true
false
The [Link]() method converts string into Boolean object. Let's see the simple code to
convert String to Boolean in java.

 Java Convert boolean to String

We can convert boolean to String in java using [Link](boolean) method.

Alternatively, we can use [Link](boolean) method which also converts boolean into
String.

1) [Link]()

The [Link]() method converts boolean to String. The valueOf() is the static method of
String class. The signature of valueOf() method is given below:

1. public static String valueOf(boolean b)

Java boolean to String Example using [Link]()

Let's see the simple example of converting boolean to String in java.

public class BooleanToStringExample1{


public static void main(String args[]){
boolean b1=true;
boolean b2=false;
String s1=[Link](b1);
String s2=[Link](b2);
[Link](s1);
[Link](s2);
}}

Output:

true
false

2) [Link]()

The [Link]() method converts boolean to String. The toString() is the static method of
Boolean class. The signature of toString() method is given below:

1. public static String toString(boolean b)

Java Convert Date to Timestamp

We can convert Date to Timestamp in java using constructor of [Link] class.

The constructor of Timestamp class receives long value as an argument. So you need to convert
date into long value using getTime() method of [Link] class.

You can also format the output of Timestamp using [Link] class.

Constructor of Timestamp class:

1. Timestamp(long l)

getTime() method of Date class:

1. public long getTime()


Java Date to Timestamp Example
import [Link];
import [Link];
public class DateToTimestampExample1 {
public static void main(String args[]){
Date date = new Date();
Timestamp ts=new Timestamp([Link]());
[Link](ts);
}
}

Output:

2017-11-02 [Link].274

 Java Convert Timestamp to Date

We can convert Timestamp to Date in java using constructor of [Link] class.

The constructor of Date class receives long value as an argument. So, you need to convert
Timestamp object into long value using getTime() method of [Link] class.

the constructor of Date class and signature of getTime() method.

1. Date(long l)

getTime() method of Timestamp class:

1. public long getTime()

Java Timestamp to Date Example

the simple example to convert Timestamp to Date in java.

import [Link];
import [Link];
public class TimestampToDateExample1 {
public static void main(String args[]){
Timestamp ts=new Timestamp([Link]());
Date date=new Date([Link]());
[Link](date);
}
}

Output:

Thu Nov 02 [Link] IST 2017

 Java Convert Binary to Decimal

We can convert binary to decimal in java using [Link]() method or custom logic.

Java Binary to Decimal conversion: [Link]()

The [Link]() method converts string to int with given redix. The signature of parseInt()
method is given below:

1. public static int parseInt(String s,int redix)

public class BinaryToDecimalExample1{


public static void main(String args[]){
String binaryString="1010";
int decimal=[Link](binaryString,2);
[Link](decimal);
}}

Output:

10
public class BinaryToDecimalExample2{
public static void main(String args[]){
[Link]([Link]("1010",2));
[Link]([Link]("10101",2));
[Link]([Link]("11111",2));
}}

Output:

10
21
31
 Java Convert Decimal to Binary

We can convert decimal to binary in java using [Link]() method or custom


logic.

Java Decimal to Binary conversion: [Link]()

The [Link]() method converts decimal to binary string. The signature of


toBinaryString() method is given below:

1. public static String toBinaryString(int decimal)

public class DecimalToBinaryExample1{


public static void main(String args[]){
[Link]([Link](10));
[Link]([Link](21));
[Link]([Link](31));
}}

Output:

1010
10101
11111

 Java Convert Hexadecimal to Decimal

We can convert hexadecimal to decimal in java using [Link]() method or custom


logic.
Java Hexadecimal to Decimal conversion: [Link]()

The [Link]() method converts string to int with given redix. The signature of parseInt()
method is given below:

1. public static int parseInt(String s,int redix)


the simple example of converting hexadecimal to decimal in java.
public class HexToDecimalExample1{
public static void main(String args[]){
String hex="a";
int decimal=[Link](hex,16);
[Link](decimal);
}}

Output:

10

another example of [Link]() method.

public class HexToDecimalExample2{


public static void main(String args[]){
[Link]([Link]("a",16));
[Link]([Link]("f",16));
[Link]([Link]("121",16));
}}

Output:

10
15
289

 Java Convert Decimal to Hexadecimal

We can convert decimal to hexadecimal in java using [Link]() method or custom


logic.
Java Decimal to Hex conversion: [Link]()

The [Link]() method converts decimal to hexadecimal. The signature of


toHexString() method is given below:

1. public static String toHexString(int decimal)

example of converting decimal to binary in java.

public class DecimalToHexExample1{


public static void main(String args[]){
[Link]([Link](10));
[Link]([Link](15));
[Link]([Link](289));
}}

Output:.

a
f
121

 Java Convert Octal to Decimal

convert octal to decimal in java using [Link]() method or custom logic.

Java Octal to Decimal conversion: [Link]()

The [Link]() method converts a string to an int with the given radix. If you pass 8 as a
radix, it converts an octal string into decimal. Let us see the signature of parseInt() method:

1. public static int parseInt(String s,int radix)

example of converting octal to decimal in java.

//Java Program to demonstrate the use of [Link]() method


//for converting Octal to Decimal number
public class OctalToDecimalExample1{
public static void main(String args[]){
//Declaring an octal number
String octalString="121";
//Converting octal number into decimal
int decimal=[Link](octalString,8);
//Printing converted decimal number
[Link](decimal);
}}

Output:

81
another examp//Shorthand example of [Link]() method
public class OctalToDecimalExample2{
public static void main(String args[]){
[Link]([Link]("121",8));
[Link]([Link]("23",8));
[Link]([Link]("10",8));
}}

Output:le of [Link]() method.

81
19
8

 Java Convert Decimal to Octal

convert decimal to octal in java using [Link]() method or custom logic.

Java Decimal to Octal conversion: [Link]()

The [Link]() method converts decimal to octal string. The signature of


toOctalString() method is given below:
1. public static String toOctalString(int decimal)

example of converting decimal to octal in java.

//Java Program to demonstrate the use of [Link]() method


public class DecimalToOctalExample1{
public static void main(String args[]){
//Using the predefined [Link]() method
//to convert decimal value into octal
[Link]([Link](8));
[Link]([Link](19));
[Link]([Link](81));
}}

Output:

10
23
121

You might also like