ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2024 ICSE Computer Science Paper



Share with a Friend

Solved 2024 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Gmail ID Validation Program - ICSE 2024 Computer Science

Question 8
Define a class to accept the Gmail ID and check for its validity.


A Gmail ID is valid only if it has:
 @
 . (dot)
 gmail
 com

Example: icse2024@gmail.com is a valid Gmail ID.

import java.util.Scanner; class Gmail{ public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.print("Enter the Gmail ID: "); String gm = in.nextLine(); boolean check = true; if(!gm.endsWith("@gmail.com")) check = false; else{ String first = gm.substring(0, gm.lastIndexOf('@')); if(first.length() == 0) check = false; for(int i = 0; i < first.length(); i++){ char ch = first.charAt(i); if(!Character.isLetterOrDigit(ch)){ check = false; break; } } } if(check) System.out.println("Valid Gmail ID!"); else System.out.println("Invalid Gmail ID."); } }

Output

 
 OUTPUT : 
Enter the Gmail ID: icse2024@gmail.com
Valid Gmail ID!