Advertisement
IvonLiu

Scanner demo

Jul 20th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.41 KB | None | 0 0
  1. public class ScannerDemo {
  2.    
  3.     public static void main(String[] args) {
  4.         Scanner scanner = new Scanner(System.in);
  5.         String s = scanner.nextLine();
  6.         int i = scanner.nextInt();
  7.         double d = scanner.nextDouble();
  8.         // etc., get other things from scanner
  9.        
  10.         // make sure to close scanner when you are done with it
  11.         // important: you cannot reopen the scanner again after you close it
  12.         scanner.close();
  13.     }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement