SHARE
TWEET

Untitled

a guest Jun 26th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Type your age: hello
  2. Type your age: ?
  3. Type your age: 3.14
  4. Type your age: 25
  5. Type your GPA: a
  6. Type your GPA: bcd
  7. Type your GPA: 2.5
  8. age = 25, GPA = 2.5
  9.      
  10. Type your age: hello
  11. Type your age: ?
  12. Type your age: 3.14
  13. 25
  14. Type your GPA: a
  15. Type your GPA: bcd
  16. 2.5
  17. age = 25, GPA = 2.5
  18.      
  19. Scanner console = new Scanner(System.in);
  20. System.out.print("Type your age: ");
  21. console.next();
  22. while (!console.hasNextInt()) {
  23.   System.out.print("Type your age: ");
  24.   console.next();
  25. }
  26. int age = console.nextInt();
  27.  
  28. System.out.print("Type your GPA: ");
  29. console.next();
  30. while (!console.hasNextDouble()) {
  31.   System.out.print("Type your GPA: ");
  32.   console.next();
  33. }
  34. double gpa = console.nextDouble();
  35. System.out.println("age = " + age + ", GPA = " + gpa);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top