Looping through variables in JAVA -
it possible loop through variables of primitive type char (using foreach loop)?
i have 3 characters
char char1 = 'a'; char chartest = 'p'; char character = 'r';
currently have long list of "if" statements applied char1:
if (char1 == 'a') dosomething; else if (char1 == 'k') dosomethingelse; else if (charprev == 'g') dosomethingagain; else dosomethingyetagain;
however, applying same set of "if" statements other character variables (in example chartest , character).
what way accomplish this? input!
the easiest way put variables array , loop through them. like
char[] chararray = {char1, chartest, character}; // says, each char in chararray (char character : chararray) { if (character == 'a') // else if (character == 'k') // else // }
Comments
Post a Comment