Advertisement
cd62131

Sample Scanner (String to Integer)

Nov 2nd, 2013
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.48 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.   /**
  5.    * @param args
  6.    */
  7.   public static void main(String[] args) {
  8.     Scanner in = new Scanner(System.in);
  9.     int x, y;
  10.     while (true) {
  11.       System.out.print("x, y ?");
  12.       try {
  13.         x = new Integer(in.next());
  14.         y = new Integer(in.next());
  15.         break;
  16.       }
  17.       catch (Exception e) {
  18.         continue;
  19.       }
  20.     }
  21.     in.close();
  22.     System.out.println(x);
  23.     System.out.println(y);
  24.   }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement