java - How to convert String input into int and push into a Stack -


for example, have string "12,456,544,233" user input,

i want take each number separated commas , push each 1 stack, converting int in process because stack . (array implementation of stack way)

so 12 @ 0, 456 @ 1, 544 @ 2, etc...

i know have use integer class parse, not sure how setup loop everything, if didn't provide enough info, ask , so! thanks.

the code tried:

string input = scan.nextline();      stack.push(integer.parseint(string.valueof(input.charat(2)))); 

here how can split strings

string string = "12,456,544,233"; string[] individualstrings = string.split(","); 

split() method splits string around matches of given regular expression.

next, can interate on string array , convert each element integer.

for(int = 0; < individualstrings.length; i++) {   int m = integer.parseint(individualstrings[i]); } 

cheers !!


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -