Write a Java Program to convert string type variables into int

Write a Java Program to convert string type variables into int

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
class Main {
  public static void main(String[] args) {

    // create string variables
    String str1 = "23";
    String str2 = "4566";

    // convert string to int
    // using parseInt()
    int num1 = Integer.parseInt(str1);
    int num2 = Integer.parseInt(str2);

    // print int values
    System.out.println(num1);    // 23
    System.out.println(num2);    // 4566
  }
}

Final output

Leave a Comment