Write a method header on line two with the following specs:
Returns: a String
Name: makeThreeSubstr
Parameters:
-
a String called "word"
-
an integer called "startIndex"
-
an integer called "endIndex"
Then, starting on line 4, write code that will return 3x the substring (no spaces) from "startIndex" to "endIndex"
Examples:
-
makeThreeSubstr("hello",0,2) ==> "hehehe"
-
makeThreeSubstr("shenanigans",3,7) ==> "naninaninani"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
class Main {
public static String makeThreeSubstr(String word, int startIndex, int endIndex)
{
String temp="";
for(int i=0;i<3;i++) {
temp+=word.substring(startIndex,endIndex);
}
return temp;
}
//test case below (dont change):
public static void main(String[] args){
System.out.println(makeThreeSubstr("hello",0,2)); //should be hehehe
System.out.println(makeThreeSubstr("shenanigans",3,7)); //should be naninaninani
}
}
|
반응형
'Java_beginner(Repl.it) > Auto-Graded-Course(AP CS A)' 카테고리의 다른 글
045 - Accumulator Method Practice 1 (0) | 2019.12.19 |
---|---|
044 - Method Header Challenge 1 (Optional) (0) | 2019.12.19 |
042 - Method Header Practice 7 (0) | 2019.12.19 |
041 - Method Header Practice 6 (0) | 2019.12.19 |
040 - Method Header Practice 5 (0) | 2019.12.19 |