You are viewing a single comment's thread. Return to all comments →
**This code is written by doing validations for inputs.
public class Solution {
public static void main(String[] args) { Scanner in = new Scanner(System.in); String S = in.next(); int start = in.nextInt(); int end = in.nextInt(); System.out.println(sub(S,start,end)); } public static String sub(String s,int a,int b) { int d =0; if(s==null || s.isEmpty()) return "Invalid"; if(a<0 || a>b) return "Invalid"; for(int i=0;i<s.length();i++) { char c = s.charAt(i); if((c>=65 && c<=97) || (c>=97 && c<=122)) d++; else return"Invalid"; } s=s.substring(a,b); return s; }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Java Substring
You are viewing a single comment's thread. Return to all comments →
**This code is written by doing validations for inputs.
public class Solution {
}