计算已完成的数独板的行数和列数
所以我试图计算已完成的数独板的输入文件有多少行和列。我想出了这个循环,
public static Pair<Integer, Integer> rowColumnCount(Scanner input1){
int nrows=0;
int ncolumns=0;
while(input1.hasNextLine()){
while(input1.hasNextInt()){
input1.nextInt();
ncolumns++;
}
input1.nextLine();
nrows++;
}
System.out.print("Rows: " +nrows + "\n");
System.out.print("Columns: " +ncolumns + "\n");
return new Pair<Integer, Integer>(nrows, ncolumns);
}//end rowCoulmnCount
我想从我之前的方法中创建这个方法,在这个方法中我读取并创建了数独板输入文件的数组。我认为这两种方法是相似的,但它们不是.. nrws 和 ncolumns 的输出是 1 & 81. 那么有人可以帮我找出正确的方法来计算列数以确保有 9 个。或者最好开始比较行和列的值以查看是否有任何重复项(1-9)使用错误检查来查看是否有正确的行数和列数?
So im trying to count how many rows and columns an input file of a completed sudoku board has. I've come up with this loop
public static Pair<Integer, Integer> rowColumnCount(Scanner input1){
int nrows=0;
int ncolumns=0;
while(input1.hasNextLine()){
while(input1.hasNextInt()){
input1.nextInt();
ncolumns++;
}
input1.nextLine();
nrows++;
}
System.out.print("Rows: " +nrows + "\n");
System.out.print("Columns: " +ncolumns + "\n");
return new Pair<Integer, Integer>(nrows, ncolumns);
}//end rowCoulmnCount
I got the idea to make this method from a previous method I have in which I read and created an array of the sudoku board input file. I figured the two methods would be similar, but they're not.. the outpuut of nrws and ncolumns is 1 & 81. So could someone help me figure out the proper way to count columns to make sure there are 9. Or would it be better to start comparing the values of the rows and columns to see if there are any duplicates (of 1-9) in use that error checking to see if there are the correct number of rows and columns?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
try: