I want to create a class that would return an array of pairs that have the same length as the input array of strings.
In addition, the pair should have the first letter of the string and length of the string.
for example;
create(new String[] {"clue", "yay", "neon", "halala"})
should return the array of Pairs
{[’c’,4],[’y’,3],[’n’,4],['h',6]}
So, my input and output would both be arrays. But the output has to be in the form of a pair. Here's what i tried:
import java.util.Arrays;
public class Couple {
public static Couple[] create(String[] source){
for (int i = 0; i < source.length; i++) {
System.out.print("["+","+source.length+"]") ;
}
return null;
}
public static void main(String[] args) {
System.out.println(Arrays.toString(create(new String[] {"clue", "yay", "neon", "halala"})));
}
}
as it's obvious there are a few errors+ i dont want it to return null. But just for the sake of testing this code, i had to do it.
Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…