You are viewing a single comment's thread. Return to all 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(); } }
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
Java String Tokens
You are viewing a single comment's thread. Return to all comments →
What is wrong with this code: import java.io.; import java.util.;
public class Solution {
} 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)
} scan.close(); } }