gpt4 book ai didi

java - 如何不考虑表中的重复值

转载 作者:行者123 更新时间:2023-12-01 14:06:38 24 4
gpt4 key购买 nike

我正在实现一个 JTable,用户可以在其中定义时间表。每个科目都有多个学分,我必须统计一周内所有学分的总和。显然,为此,有必要将所有重复主题计算一次(我不会将同一主题的学分计算两次)。

例如,如果 JTable 是 Imagine of an example TimeTable

我想获取值数学英语科学哲学艺术一次次。我尝试使用 follower 方法来做到这一点:

private void getOnce (String[] dailyLessons)
{
Set<String> weekSubjects = new HashSet<String>();
int weeklyCredits=0;

//dailylessons is a String[] that contains the lessons of the day
Collections.addAll(weekSubjects, dailyLessons);

//String[] week would contain every subject only one time
String [] week = weekSubjects.toArray(new String[0]);

//for all the subject I get its credits
for (int i=0; i<week.length; i++)
{
if (!week[i].equals("no"))
{
String [] credits= week[i].getCredits;
weeklyCredits += credits;
}
}
}

但是它不起作用。你能解释一下为什么吗?我的代码的正确版本将非常感激。

最佳答案

But it does not work. Could you explain me why?

A correct version of my code will be very appreciated.

  • 不错

关于java - 如何不考虑表中的重复值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18847082/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com