【发布时间】:2018-08-13 21:07:59
【问题描述】:
我是 Java 新手,我正在尝试构建一组像这样的元组:
Slegs = {<1,2,500> , <2,5,400>, <5,7,850>, <2,3,450>}等
然后,定义其他数组,如:
int u [Slegs][G];
例如:
u[<1,2,500>][1] = 80
u[<2,5,400>][1] = 80
u[<1,2,500>][2] = 65
u[<2,5,400>][2] = 130
等等
为此,我编码如下:
public class Model {
public static int Y = 7;
public static int K = 42;
public static int G = 3;
class Sleg {
public int i;
public int j;
public double l;
List<Sleg> Slegs = new ArrayList<Sleg>();
Map <Integer, Sleg> slTup = new HAshMap<Integer, Sleg>();
int[][] u = new int [key][G]; /* I want to define and use a key here*/
}
我的问题是我不知道如何将这些元组添加到 slTup 的 for 循环中,以及如何为它们分配一个键,以便我可以使用该键来定义 u[key][G]; 以及,如何断言/定义 i 和 j 在 Y 中,i !=j 在每个元组 <i,j,l> 中;
如果您可以使用上面给定的理论数据实例化并打印出 u[key][g],我将不胜感激。
【问题讨论】: