Guessing the Primary Class Name of Java

Sort by

recency

|

2 Discussions

|

  • + 0 comments

    I have written a code which runs fine on my JAVA IDE, but saying ~no response~ in the output on the site. The code is given below:

    import java.io.*;
    import java.util.*;
    import java.text.*;
    import java.math.*;
    import java.util.regex.*;
    
    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. */
            
            String the1Regex = "\\bpublic\\sclass\\b";
    		String the2Regex = "\\bmain\\b";
            Scanner sc = new Scanner(System.in);
            String inputString = sc.next();
            
            Pattern checkRegex = Pattern.compile(the1Regex);
    		Pattern checkRegex1 = Pattern.compile(the2Regex);
    		Matcher regexMatcher = checkRegex.matcher(inputString);
    		Matcher regexMatcher1 = checkRegex1.matcher(inputString);
    			if(regexMatcher.find()){
    			if(regexMatcher.group().length() != 0){
    					System.out.println(inputString.substring(regexMatcher.end()+1, inputString.indexOf('{'))); 
    			}
               }
    			else 
    				if(regexMatcher1.find()){
    				if(regexMatcher1.group().length()!=0){
    				System.out.println(inputString.substring(0,regexMatcher1.start()).substring(
    						inputString.substring(0,regexMatcher1.start()).indexOf('c')+6, 
    						inputString.substring(0,regexMatcher1.start()).indexOf('{')));
    			}
               }
    	   }
    }
    
  • + 1 comment

    I have done with primary class AA and a method classname and got a proper answere but still it's showing wrong answere. why?

No more comments