-
Notifications
You must be signed in to change notification settings - Fork 54
/
Question3.txt
42 lines (39 loc) · 3.44 KB
/
Question3.txt
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Question 3
Write a function that accepts a character array, a zero-based start position and
a length. It should return a character array containing lengthCharacters starting with
the startCharacter of the input array. The function should do error checking on the start
position and the length and return null if the either value is not legal.
The function signature is:
char[] f(char[] a, int start, int len)
--------------------------------|--------------------------------------------------------------
| if the input parameters are is | return |
|--------------------------------|--------------------------------------------------------------|
| {'a','b','c'}, 0, 4 | null |
|--------------------------------|--------------------------------------------------------------|
| {'a','b','c'}, 0, 3 | {'a','b','c'} |
|--------------------------------|--------------------------------------------------------------|
| {'a','b','c'}, 0, 2 | {'a','b'} |
|--------------------------------|--------------------------------------------------------------|
| {'a','b','c'}, 0, 1 | {'a'} |
|--------------------------------|--------------------------------------------------------------|
| {'a','b','c'}, 1, 3 | null |
|--------------------------------|--------------------------------------------------------------|
| {'a','b','c'}, 1, 2 | {'b','c'} |
|--------------------------------|--------------------------------------------------------------|
| {'a','b','c'}, 1, 1 | {'b'} |
|--------------------------------|--------------------------------------------------------------|
| {'a','b','c'}, 2, 2 | null |
|--------------------------------|--------------------------------------------------------------|
| {'a','b','c'}, 2, 1 | {'c'} |
|--------------------------------|--------------------------------------------------------------|
| {'a','b','c'}, 3, 1 | null |
|--------------------------------|--------------------------------------------------------------|
| {'a','b','c'}, 1, 0 | {} |
|--------------------------------|--------------------------------------------------------------|
| {'a','b','c'}, -1, 2 | null |
|--------------------------------|--------------------------------------------------------------|
| {'a','b','c'}, -1, -2 | null |
|--------------------------------|--------------------------------------------------------------|
| {}, 0, 1 | null |
-----------------------------------------------------------------------------------------------
NOTE: To ease debugging, i will return string containing the characters