Q:

Write a Java program to convert a string to an integer in Java

0

Write a Java program to convert a string to an integer in Java
Sample Output:

Input a number(string): 25                                             
The integer value is: 25

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.*;
public class Exercise51 {

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

Sample Output:

Input a number(string): 25                                             
The integer value is: 25

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now