In this section, you will learn to convert a string type data into an integer type. The java.lang package provides the functionality to convert the string type data into an integer type data.
Code Description:
This program takes a string type data on the console and converts it into an integer. Data at the console is as a string type so, it must be converted into an integer type using the parseInt() method. This method converts the string type number into an integer format. Whenever you give the string type data as 's' then the exception must be thrown.
parseInt():
The parseInt() method parses the string parameter as a signed decimal integer. This
method is used to convert an integer type data into a string type data.
Here is the code of this code:
import java.io.*;
|
Output this program.
| C:\vinod\convert>javac StringToInt.java C:\vinod\convert>java StringToInt Enter an integer number: 10 String: 10 Integer: 10 |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Convert a String into an Integer Data View All Comments
Post your Comment