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
Post a Comment