-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path37.2 gmail validator.java
74 lines (58 loc) · 1.72 KB
/
37.2 gmail validator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
Ask the user to give his/her the Gmail id , check Gmail id is in proper format or not ? and count the number of charecters excluding @gmail.com
let rules for valid mail id are
1. only special symbol allowed is (.) and that must not be in staring or ending.
2. @gmail.com must be prsent at last.
Input Format
First line must be a mail id
for Example
Input Format
bhimasen.moharana@gmail.com
Output Format
valid 17
Constraints
input must be a Gmail id
Output Format
First line prints "valid" or "invalid"
Secondline prints Number of chars presenst inthe mail id excluding @gmail.com
Sample Input 0
bhimasen.moharana@lpu.co.in
Sample Output 0
invalid
17
Explanation 0
invalid because it is not a Gmail id.
and number of charecter =17
*/
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
String gmail = sc.next();
char []check = gmail.toCharArray();
boolean ans = true;
int count =0;
if(gmail.endsWith("@gmail.com"))
{
int n = gmail.indexOf("@gmail.com");
for(int i=0;i<n;i++)
{
if(!((check[i] >= 'A' && check[i] <= 'Z') || (check[i] >='a') && (check[i] <= 'j')))
{
System.out.println("invalid");
ans = false;
}
}
if(ans)
System.out.println("valid");
}
else
{
System.out.println("invalid");
}
int ct = gmail.indexOf("@");
System.out.print(ct);
}
}