【发布时间】:2017-08-17 15:03:45
【问题描述】:
这是我的主题矩阵....现在我想在主题之间设置条件
mat pro
mat null null
pro null null
例如,在主题数学上,我在主题 programing 上插入了 semester =1 的主题值,我输入了 semester = 4,所以我想用“yes”填充这个矩阵,前提是第一个主题的 semester 是大于第二个科目的学期和“no”如果不是...现在我遇到的问题是我可以输入组合条件:
math - math , which would be "no"
math - programing , which would be "no"
programing - programing , which would be "no"
程序完成后是这样的:
mat pro
mat no no
pro no no
但我没有要求这种组合设置条件: 编程 - 数学,这将是“是” 它应该看起来像这样:
mat pro
mat no no
pro yes no
我该如何做到这一点?有什么想法吗?
这是我的代码:
public void makeGraph() {
matrix = new String[subjects.size()][subjects.size()];
for (int i = 0; i < matrix.length; i++) {
for (int j = i; j < matrix.length; j++) {
System.out.println("Enter conditionality between subjects: " + subjects.get(i).getName() + ", and "
+ subjects.get(j).getName());
boolean conditioned = s.nextBoolean();
if (conditioned == true) {
if (subjects.get(i).getSemester() > subjects.get(j).getSemester()) {
matrix[i][j] = "yes";
matrix[j][i] = "yes";
} else {
matrix[i][j] = "no";
matrix[j][i] = "no";
}
} else {
matrix[i][j] = "no";
matrix[j][i] = "no";
}
}
}
}
编辑:这是我已经解决的 pastebin 的链接。 Solution
【问题讨论】:
-
你的帖子写得太差了,请努力..
-
@azro 很抱歉,我知道但我无法理解,尝试正确编写时它对我不起作用。
-
如果我的解决方案有帮助,您能否通过单击我的答案旁边的灰色复选标记将其变为绿色来接受它?此外,非常感谢点击我的答案旁边的箭头:)
-
@Assafs 我什至没看你回答..当我完成解决方案时才看到它......现在我明白你在答案中的意思与我想的一样,它是一个很好的练习,我想哈哈哈,是的,我会点击复选标记和箭头:)。
标签: java matrix combinations