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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -