java - How to split a String into integers? -
I would like to split a string, and I want to store every digit of the string in an integer.
Here is my test code:
public class test {public static zero main (string [] args) {int firstGuessDigit, secondGuessDigit, thirdGuessDigit, fourthGuessDigit; String estimate = "1234"; String [] parts = estimate. Split ("\"); FirstGuessDigit = integer Parasont (part [0]); Second cosgit = integer Parasont (part [1]); Third Guszdigit = integer.center (part [2]); Fourthoguesdegit = integer.print (part [3]); }}
When I run the program, I get an error: "Exception in thread" main "java.lang.ArrayIndexOutOfBoundsException: 1 test.main (test.java11)
You can use string # toCharArray
instead:
four [] parts = estimate: kocharayre (); first gusadigit = integer paracetant (character string (parts [0])); secondguidedegit = integer. Parasent (character part (part [1]) ; Third Guse Diagram = Flood Nankkprsent (characters. Tusting (part [2])); Chauthagusdigit = integer. Pirisaint (character. To string (Part [3]));
Comments
Post a Comment