Write a Java program to convert a string to an integer

Program

import java.util.*;

public class Demo {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        System.out.print("Input a number (string): ");
        String str = s.nextLine();
        int result = Integer.parseInt(str);
        System.out.printf("The integer value is: %d", result);
    }
}	 

Output:

Input a number (string): 24

The integer value is: 24

For latest job updates join Telegram Channel: https://t.me/sateeshm

Programs