我正在從_(1-9)間隔的文件中讀取數據,然後用每個數字對堆棧進行一些操作。我只是試圖讓我的案例閱讀數組中的每個項目,併爲每個數字做些事情,但我似乎無法讓它工作。我無法讓我的堆棧工作
public static void main(String[] args) throws FileNotFoundException {
FileReader file = new FileReader("textfile.txt");
int[] integers;
integers = new int[100];
int i = 0;
try (Scanner input = new Scanner(file)) {
while (input.hasNext()) {
integers[i] = input.nextInt();
i++;
}
Stack<Integer> nums = new Stack<>();
int number = integers[i];
switch (number) {
case '1':
nums.push(5);
System.out.println(nums.peek());
break;
}
} catch (Exception e) {
}
}
你的具體問題是什麼? –