HackerRank Java- Substring

Given a string, S, and two indices, start and end, print a substring consisting of all characters in the inclusive range from start to end-1. You'll find the String class' substring method helpful in completing this challenge.

  1. import java.io.*;
  2. import java.util.*;
  3. import java.text.*;
  4. import java.math.*;
  5. import java.util.regex.*;
  6. public class Solution {
  7. public static void main(String[] args) {
  8. Scanner scan = new Scanner(System.in);
  9. String str = scan.next();
  10. int start = scan.nextInt();
  11. int end = scan.nextInt();
  12. scan.close();
  13. System.out.println(str.substring(start, end));
  14. }
  15. }


Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube