In this section, you will learn to convert the character into a integer. The java.lang package convert provides the facility to convert the character data into an integer type.
Convert Character into Integer
In this section, you will learn to convert the character into a integer. The java.lang package convert provides the facility to convert the character data into an integer type.
Description of code:
This program helps you to convert the character data into an integer type data. It defines a class name "CharToInt" and takes a character on the console. The given character is converted into an integer using the parseInt() method. It parses the string argument as a signed Integer value. Whenever the given character isn't numeric, it displays a message " Not a numeric!".
Here is the code of this program:
import java.io.*;
|
Output of this program.
C:\vinod\xml\convert>javac CharToInt.java C:\vinod\xml\convert>java CharToInt Enter a char: S Char: S Not a numeric! C:\vinod\xml\convert>java CharToInt Enter a char: 8 Char: 8 Integer: 8 |