Advertisement
SenpaiZero

Untitled

May 9th, 2024
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.43 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         String user;
  6.         Scanner scanner = new Scanner(System.in);
  7.         do {
  8.             System.out.print("Student Number: ");
  9.             user = scanner.nextLine();
  10.            
  11.             if(user.matches("[0-9]{4}-[0-9]{2}-[0-9]{3}"))
  12.                 break;
  13.            
  14.             System.out.println("Invalid student number.");
  15.         } while(true);
  16.        
  17.         System.out.println("Your student number is " + user);
  18.     }
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement