Java Data Type How to - Convert string to integer








Question

We would like to know how to convert string to integer.

Answer

//from  ww  w.j  av  a 2  s  . c om

class Main {
  public static void main(String[] args) {
    int x, y;

    x = Integer.parseInt("1");
    y = Integer.parseInt("2");

    if (x > y) {
      System.out.println(x + " + y);
    } else if (x < y) {
      System.out.println(x + "<" + y);
    } else {
      System.out.println(x + "=" + y);
    }
  }
}