Java - Convert string type to integer type

Description

Convert string type to integer type

Demo

import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int n = Integer.parseInt(sc.nextLine());
      System.out.println(n);//from  w ww.j  a v a2 s.  c om

    } catch (NumberFormatException e) {
      System.out.println("Bad String");
    }
  }
}

Related Topic