Java String Tokens

Sort by

recency

|

1754 Discussions

|

  • + 0 comments

    A notable advantage is the support for local regulations and codes. Springfield, like many cities, has specific rules regarding waste disposal, especially for construction debris, hazardous materials, or large volumes of household junk. Professional dumpster rental companies are well-versed in these regulations and can help ensure you’re in compliance learn more. This takes a major burden off your shoulders, as it reduces the risk of fines or delays in your project due to improper waste handling.

  • + 0 comments

    What is wrong with this code: import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.nextLine();
        // Write your code here.
        int counter=0;
        int flag=1;
        boolean lastWasChar = false;
        String comp="!,?._'@ ";
        for(int i=0;i<s.length();i++){
            if(comp.contains(s.substring(i, i+1))){
                if((i+2)<s.length()){
                if(comp.contains(s.substring(i+1, i+2))){
                    if(flag==1){
                        counter++;
                        flag=0;
                    }
                    continue;
                }
                }
                if(flag==1){
                    counter++;
                }
                flag=1;
            }
            else {
        lastWasChar = true;
    }
        }
        if (lastWasChar && !comp.contains(s.substring(s.length() - 1))) {
    counter++;
    

    } lastWasChar = false; System.out.println(counter); int ref=0; flag =1; for(int i=0;i if(comp.contains(s.substring(i, i+1))){ if((i+2)

                ref=i+1;
                flag=1;
            }
                        else {
        lastWasChar = true;
    }
        }
                    if (lastWasChar && !comp.contains(s.substring(s.length() - 1))) {
    System.out.println(s.substring(ref, s.length()));
    

    } scan.close(); } }

  • + 0 comments

    Easy Working for all test cases

    Scanner sc = new Scanner(System.in);
            
            String sent=sc.nextLine().trim();
            if(sent.length()>0){
                String [] words = sent.split("[ !,?._'@]+");
                System.out.println(words.length);
                for (String word:words)
                    System.out.println(word);
            }else{
                System.out.println(0);
            }
            sc.close();
    
  • + 0 comments
    public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            String s = scan.nextLine();
            String[] strArray = s.split("[ !,?._'@]");
             strArray = Arrays.stream(strArray)
                         .filter(str -> !str.isEmpty())
                         .toArray(String[]::new);
            System.out.println(strArray.length);
            Arrays.stream(strArray).forEach(e->System.out.println(e));
            scan.close();
        }
    
  • + 0 comments
    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            String s = scan.nextLine().trim();
            if(s.isEmpty())
            {
                System.out.println("0");
            }
            else
            {
            
            String[]arr=s.split("[ ,!?._'@]+");
            int count=arr.length;
            System.out.println(count);
            for(int i=0;i<arr.length;i++)
            {
                System.out.println(arr[i]);
            }
            } 
            scan.close();
            
        }
    }