Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.InputMismatchException;
  3.  
  4. public class NameAgeChecker {
  5. public static void main(String[] args) {
  6. Scanner scnr = new Scanner(System.in);
  7.  
  8. String inputName;
  9. int age;
  10.  
  11. inputName = scnr.next();
  12. while (!inputName.equals("-1")) {
  13. try {
  14.  
  15. age = scnr.nextInt();
  16. System.out.println(inputName + " " + (age + 1));
  17.  
  18. inputName = scnr.next();
  19. }
  20. catch(InputMismatchException e){
  21.  
  22. System.out.println(inputName + " 0" );
  23. inputName = scnr.next();
  24. String temp = scnr.next();
  25.  
  26.  
  27.  
  28. }
  29.  
  30.  
  31.  
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement