|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
1. Given class Test as follows. Please complete the program such that it can run correctly and output the result as follws.
John’s friend is Mary
Mary’s friend is John
public class Test{
public static void main(String[ ] args){
Person john =new Person(“John”);
Person mary =new Person(“Mary”);
john.setFriend(mary);
System.out.println(john.getInfo());
System.out.println(mary.getInfo());
}
}
写了部分 后面差的的如何补上呢!
2.Given class Test as follows. Please complete the program such that it can run correctly
and output the result as follows.
[Trump’s:1, elsest:1, son:1, has:1, positive:1, for:1, the:1, coronavirus:1]
Import java.util.*;
Public class Test{
private static Weword addTo(Weword w.ArrayList list){
for(int i = 0;i < list.size();i++) if(w.equals (list.get(i))) return list.get(i);
list.add(w);
return w;
public static void main(String[] args){
String line = “Trump’s eldest son has tested positive for the coronavirus”;
String[] words = line.split(“ “);
ArrayList list = new ArrayList();
for(int i = 0;i < words.length;i++){
Weword w = addTo(new Weword(words[i]),list);
w.num++;
}
System.out.println(list);
}
非常非常感谢! |
|