java - My loop using charAt isn't working -
i in need of loop. trying run loop. when array string champs contains character 'b' first letter display both time , champ.
could tell me i've done wrong or why isn't showing up? output receive "time champs"
public static void displayteam(short[] time, string[] champs){ system.out.println("time champs"); for(int a= 0; < time.length; a++){ char fletter=champs[a].charat(0); if("b".equals(fletter)){ system.out.println(time[a] + " " + champs[a]); } } } thanks helps , contributes.
replace this:
if("b".equals(fletter)) with this:
if('b' == fletter) it's safe use == primitive values char.
since fletter char, what's happening code rather complex. @ first glance, 1 might wonder how compiles. what's going on string.equals takes object argument. since fletter char, gets auto-boxed character object. string "b" checks see if it's equal argument, notices argument isn't string, , returns false.
Comments
Post a Comment