forked from larissalages/code_problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidUsername.java
More file actions
30 lines (26 loc) · 886 Bytes
/
ValidUsername.java
File metadata and controls
30 lines (26 loc) · 886 Bytes
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
import java.io.*;
import java.util.*;
public class ValidUsername {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = Integer.parseInt(sc.nextLine());//taking number of testcases as input
for(int i=0;i<t;i++){
boolean result = false;
String str = sc.nextLine();//taking testcases as input
//checking the conditions
if(str.length()>=8 && str.length()<=30){
if(Character.isAlphabetic(str.charAt(0))){
if(str.matches("[a-zA-Z0-9_]+")){
result = true;
}
}
}
//Printing the result
if(result){
System.out.println("Valid");
}else{
System.out.println("Invalid");
}
}
}
}