Advertisement
MoNoLidThZ

Java05.java

Nov 19th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Java05 {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         String email = "";
  7.         do {
  8.             System.out.print("Input your e-mail: ");
  9.             email = scan.nextLine().toLowerCase();
  10.         } while (checkEmail(email));
  11.         System.out.println("\nYour e-mail is "+email);
  12.  
  13.     }
  14.    
  15.     private static boolean checkEmail(String email){
  16.         int searchAt = email.indexOf('@');
  17.         if(searchAt != -1){
  18.             //ตรวจสอบว่าลงท้ายด้วย hotmail.com, gmail.com หรือ  windowslive.com
  19.             if(email.indexOf("hotmail.com") == searchAt+1){
  20.                 return false;
  21.             }else if(email.indexOf("gmail.com") == searchAt+1){
  22.                 return false;
  23.             }else if(email.indexOf("windowslive.com") == searchAt+1){
  24.                 return false;
  25.             }
  26.         }
  27.         return true;
  28.     }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement