我想解决一个问题:我有一个带有图像(20行x 20列)的0和1的随机文本文件。在每张图片(20x20)之间,都有一条空行。从txt文件中计数
基于这个txt文件,我必须计算出这些图像中有多少个比1多1。最后,我还需要在一张图片中找到1的最高数字。
这里是我的代码,那么远,但我有点失去
import java.io.File;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
File input = new File("path to my txt file");
Scanner scanner = new Scanner(new File("path to my txt file"));
int counter = 0;
while (scanner.hasNext()){
String word1 = scanner.next();
String word2 = scanner.next();
boolean switcher = false;
int howManyOnes ("//path to my image file????") {
int ones = 0;
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 20; j++) {
ones +=?[i][j];
}
}
return ones;
}
}
}
您似乎已经在方法中编写了一个方法。这不会编译? –