Valid Username Regular Expression Solution Hackerrank - Java Solution - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Tuesday, December 12, 2017

Valid Username Regular Expression Solution Hackerrank - Java Solution

Valid Username Regular Expression Solution Hackerrank - Java Solution

HackerRank Problem Solution

Problem Name - Valid Username Regular Expression
Problem Link -  Valid Username Regular Expression
Level - String

Java Only Submitted Code
class UsernameValidator {
    public static final String regularExpression = "([a-zA-Z])(\\w){7,29}";
}

Java Full Source Code
import java.util.Scanner;

class UsernameValidator {
    public static final String regularExpression = "([a-zA-Z])(\\w){7,29}";
}
public class Solution {
    private static final Scanner scan = new Scanner(System.in);
    
    public static void main(String[] args) {
        int n = Integer.parseInt(scan.nextLine());
        while (n-- != 0) {
            String userName = scan.nextLine();

            if (userName.matches(UsernameValidator.regularExpression)) {
                System.out.println("Valid");
            } else {
                System.out.println("Invalid");
            }           
        }
    }
}


Tags: HackerRank Online Judge Solution, HackerRank OJ Solution list, HackerRank Problems Solution, HackerRank solver, HackerRank all problem solution list, HackerRank solution in java, Hackerrank Java Solution, Welcome to Java!, Valid Username Regular Expression Solution Hackerrank - Java Solution

No comments:

Post a Comment