鱼C论坛

 找回密码
 立即注册
查看: 5607|回复: 3

求助两道简单的程序设计题!

[复制链接]
发表于 2021-1-10 17:10:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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);
}

非常非常感谢!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-1-10 17:15:30 | 显示全部楼层
救救孩子 感谢大佬们
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-28 05:46

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表