-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFIZZ_ARRYA2.java
More file actions
28 lines (22 loc) · 864 Bytes
/
FIZZ_ARRYA2.java
File metadata and controls
28 lines (22 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
Given a number n, create and return a new string array of length n, containing the strings "0", "1" "2" .. through n-1.
N may be 0, in which case just return a length 0 array. Note: String.valueOf(xxx) will make the String form of most types.
The syntax to make a new string array is: new String[desired_length] (See also: FizzBuzz Code)
fizzArray2(4) → ["0", "1", "2", "3"]
fizzArray2(10) → ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
fizzArray2(2) → ["0", "1"]
*/
package school;
import java.util.Arrays;
public class FIZZ_ARRYA2 {
public static void main(String[] args){
String[] answer = fizzArray2(4);
System.out.println(Arrays.toString(answer));
}
public static String[] fizzArray2(int n) {
String[] answer = new String[n];
for(int i=0; i<n; i++){
answer[i] = String.valueOf(i);
}return answer;
}
}