java - I'm not able to get my stack to work -
i reading in file numbers spaced out _ (1-9) , each number stack. i'm trying case read each item in array , each number can't seem work.
public static void main(string[] args) throws filenotfoundexception { filereader file = new filereader("textfile.txt"); int[] integers; integers = new int[100]; int = 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) { } }
in switch statement, take single quotes out number 1.
'1'
of type char
1
of type int
also, when try number here:
int number = integers[i];
it's going 0
because i
index greater you've populated in array.
Comments
Post a Comment