This program takes a string input from the user and converts it to an integer using the parseInt method of the Integer class in Java. The converted integer value is then printed as output.
Here's how the program works:
Note that if the string input is not a valid integer value, the parseInt method will throw a NumberFormatException at runtime.
import java.util.Scanner; class Convert_StringtoInt { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter the number(string): "); String str1 = input.nextLine(); int res = Integer.parseInt(str1); System.out.println("The integer value is : "+res); } }
Enter the number(string): 45 The integer value is : 45
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions