Given three variables:
String str int start int end |
Print out the following string:
The substring of (str) from (start) to (end) is (substring from start to end, inclusive)
Sample output:
In: lolwut Start: 2 End: 4 The substring of lolwut from 2 to 4 inclusive is lwu |
PLEASE NOTE that we are counting the end index in our output!
lolwut 012345 |
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
System.out.println("In:");
String str = inp.nextLine();
System.out.println("Start:");
int start = inp.nextInt();
System.out.println("End:");
int end = inp.nextInt();
// Don't change the code above! Write your code below
System.out.println("The substring of "+str+
" from "+start+" to "+end+" inclusive is "+ str.substring(start,end+1));
}
}
반응형
'Java_beginner(Repl.it) > Auto-Graded-Course(AP CS A)' 카테고리의 다른 글
016 - Conditional Statement Practice 2 (0) | 2019.11.28 |
---|---|
015 - Conditional Statement Practice 1 (0) | 2019.11.26 |
010 - String Methods Practice 1 (0) | 2019.11.26 |
009 - String Methods - substring (0) | 2019.11.26 |
008 - String Methods - indexOf (0) | 2019.11.26 |