Java 使用二维数组显示由方法填充的数据
我尝试使用2D数组来存储投票数据,并使用一维数组来存储候选人姓名、细分名称,并保存候选人和子候选人的总票数。从main方法中,我需要使用初始化列表初始化这些数组:2D数组,包含所有投票数据,但不包括总数、候选名称、细分名称,然后计算每个候选和细分的总投票数,然后打印结果 我已经开始创建初始化和填充数组所需的方法,但是为了继续,我一直在做需要做的事情Java 使用二维数组显示由方法填充的数据,java,Java,我尝试使用2D数组来存储投票数据,并使用一维数组来存储候选人姓名、细分名称,并保存候选人和子候选人的总票数。从main方法中,我需要使用初始化列表初始化这些数组:2D数组,包含所有投票数据,但不包括总数、候选名称、细分名称,然后计算每个候选和细分的总投票数,然后打印结果 我已经开始创建初始化和填充数组所需的方法,但是为了继续,我一直在做需要做的事情 { private static int[][] Data; private static String[] names; pri
{
private static int[][] Data;
private static String[] names;
private static String[] SubDivs;
private static int[] totalvoteCand;
private static int[] totalvoteSub;
// method to initialize data array
public static void InitData()
{
int[][] tempData = {{600, 800, 800, 800},
{700, 700, 700, 900},
{800, 700, 800, 700},
{400, 450, 300, 1300},
{900, 900, 900, 1000}};
Data = tempData;
String[] tempNames = { {Audrey, Brian, Elizabeth, Peter, Zachary} };
tempNames = names;
String[] tempSub = { {Aberdeen, Brock, Sahali, Valleyview} };
tempSub = SubDivs;
}// end of init
//*************************************************************//
public static void calcCandVotes() // calculates candidate votes
{
totalvoteCand = new int[data[0].length];
int tempTotal;
for(int i = 0; i<data.length;i++) {
tempTotal = 0;
for(x = 0; x<data[0].length;x++){
tempTotal += tempTotal + data[i][x];
}
totalVoteCand[i] = tempTotal;
}
}//end of calc cand
//*************************************************************//
public static void calcSubVotes() // calculates subdivision votes
{
totalvoteSub = new int[data[0].length];
int tempTotal;
for(int i = 0; i<data[0].length; i++) {
tempTotal = 0;
for(x = 0; x<data.length; x++){
tempTotal += tempTotal + data[x][i];
}
totalvoteSub[x] = tempTotal;
}
}// end of calc sub ******************************************//
public static void printArray() // print method, hopefully.
{
for(int i = 0; i<data.length;i++)
{
for (int x=0; x<data[0].length;x++)
System.out.print(Data[i][x] + "\t");
System.out.println();
}
}
//***************************end of print array****************************************
你是说你想这样印刷吗 int[][]票数={{600800800800}, {700, 700, 700, 900}, {800, 700, 800, 700}, {400, 450, 300, 1300}, {900, 900, 900, 1000}}; String[]name={Audrey,Brian,Elizabeth,Peter,Zachary}; String[]subs={Aberdeen、Brock、Sahali、Valleyview}; 系统输出打印F%-10s,候选; 对于int col=0;col