Write a method header on line two with the following specs:
Returns: a char
Name: getChar
Parameters:
-
a String called "word"
-
an integer called "index"
Then, starting on line 4, write code that will return the character in "word" at the index "index"
Examples:
-
getChar("hello",1) ==> 'e'
1
2
3
4
5
6
7
8
9
10
11
12
|
class Main {
public static char getChar(String word, int index)
{
return word.charAt(index);
}
//test case below (dont change):
public static void main(String[] args){
System.out.println(getChar("hello",1)); //should be 'e'
}
}
|
반응형
'Java_beginner(Repl.it) > Auto-Graded-Course(AP CS A)' 카테고리의 다른 글
044 - Method Header Challenge 1 (Optional) (0) | 2019.12.19 |
---|---|
043 - Method Header Practice 8 (0) | 2019.12.19 |
041 - Method Header Practice 6 (0) | 2019.12.19 |
040 - Method Header Practice 5 (0) | 2019.12.19 |
039 - Method Header Practice 4 (0) | 2019.12.19 |