我想解決一個問題:我有一個帶有圖像(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;
}
}
}
您似乎已經在方法中編寫了一個方法。這不會編譯? –