java - String array converting to integer -
this question has reply here:
how set switch statement in while loop in java 3 answersi have chunk of code i've been having problems with:
int n = 5; string[] variables = new string[31]; //user input defining strings in array for(int = 1; < n+1; i++) { system.out.print("define variable " + + ": "); variables[i] = system.console().readline(); system.out.println("variable " + + " has been set " + variables[i]); } int vfirstdigit; //some irrelevant code excluded for(int firstdigit = 1; firstdigit < n+1; firstdigit++) { switch(firstdigit) { case 1: vfirstdigit = variables[1]; break; } } when phone call variables[1] in switch statement, compiler flags error, saying string array cannot converted integer. why calling specific string in array convert integer, when user input must characters? pretty sure i'm doing wrong here.
array object. need convert in number using method parseint of integer.
java arrays
No comments:
Post a Comment