Java String Tokens

Sort by

recency

|

1788 Discussions

|

  • + 0 comments

    Issue encountered on some test case Tried inputing test using test cases and have expected output

        // Write your code here.
    
        String[] Splat = s.split("[ !,?._'@]+");
        System.out.println(Splat.length);
        for(String me : Splat)
        {
            System.out.println(me);
        }
        scan.close();
    }
    

    }

  • + 0 comments

    This is a classic string manipulation and tokenization challenge, often seen in programming exercises like those on HackerRank. New Play Exchange Login

  • + 0 comments

    import java.io.; import java.util.; import java.util.regex.*; public class Solution {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.nextLine();
        scan.close();
        Pattern p = Pattern.compile("[A-Za-z]+");
        Matcher m = p.matcher(s);
    
        List<String> tokens = new ArrayList<>();
        while (m.find()) {
            tokens.add(m.group());
        }
    
        System.out.println(tokens.size());
        for (String token : tokens) {
            System.out.println(token);
        }
    }
    

    }

  • + 0 comments

    Test number 3,6,7,10 are being failed despite giving expected output in individual tests. Used java 8 and 15. Doesn't make any different

    Scanner scan = new Scanner(System.in);
    String s = scan.nextLine();
    String[] strArr = s.split("[, .'!?_@]+");
    System.out.println(strArr.length);
    for (String str: strArr) {
    	System.out.println(str);
    }
    scan.close();
    
  • + 0 comments

    The test cases 3,6,7 and 10 fail when submitted but when run individually they pass. This is a buggy issue.