You are viewing a single comment's thread. Return to all comments →
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 input = new Scanner(System.in); int count = input.nextInt(); input.nextLine(); for(int i=0;i<count;i++){ String username = input.nextLine(); if(checkUsername(username)){ System.out.println("Valid"); } else{ System.out.println("Invalid"); } } input.close(); } public static boolean checkUsername(String username){ int length = username.length(); if(length<8 || length>30){ return false; } if(!Character.isLetter(username.charAt(0))){ return false; } for(int i=1;i<length;i++){ char ch = username.charAt(i); if(!Character.isLetterOrDigit(ch) && ch!='_'){ return false; } } return true; }
}
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Valid Username Regular Expression
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.;
public class Solution {
}