【发布时间】:2015-03-05 14:34:43
【问题描述】:
任何能够引导我走向正确方向的人。我正在构建一个简单的标记程序,我从 Scanner 获取输入并将其插入到我的二维数组中。我想验证我的输入,使其不低于 0 或高于 100,但如果我的数字不正确,我不希望数组移动到下一个位置。
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);//naming the scanner
String [] student = {"Mark","Jen","Gaby","John","Michael","James"};
String [] subject = {"Digital electronics","Analogue electronics","Maths","Networks","Telecommunications",
"Computer applications","Software developemnt","Workshop"};
String [] printSub = {"Digit","Analo","Maths","Netwo","Telec","Appli","Softw","Works"};
int maxRow = 6;//setting max row amount int
int maxCol = 8;//set max column amount int
int [][] mark = new int [maxRow][maxCol];//declaring the int array and setting the row & column max.
int i = 0, j = 0;//declaring i and j for use in the for loops
int maxMark = 0;//declaring for use in if statement to find highest mark
int minMark =100;//Declaring for use in if statement to find lowest mark
for(i = 0; i < maxRow; i++)
{
for(j = 0; j < maxCol; j++)
{
System.out.print("Please enter "+student[i]+" mark for "+subject[j]+" and press return :");
mark[i][j]= input.nextInt();
}
}
for(i=0; i < maxRow; i++)
{
for(j=0; j < maxCol; j++)
{
if (i == 0 && j == 0)
{
System.out.print("Student \t");
for(int sub = 0; sub < 8; sub++)
{
System.out.print(printSub [sub]+"\t");
}
System.out.println();
System.out.println();
}
if(i < maxRow && j == 0)
{
System.out.print(student[i]+"\t \t ");
}
System.out.print(mark [i][j]+"\t");
}
System.out.println();
System.out.println();
}
}
我不是在寻找答案,而是在寻找更多的推动力,让我自己能够找出答案。
提前感谢您的帮助。
马特
【问题讨论】:
标签: java arrays multidimensional-array java.util.scanner