Re: Beginner Loop Question
Your println is executing each iteration of the loop so if you want to print it one time after the iterations are done you would.............
Re: Beginner Loop Question
got it. I move the println out of the loop statement...& I put in another if statement for the other r. I just don't get why the s.toLowerCase still print out Roar rather than roar
Re: Beginner Loop Question
you did'nt use the s.LowerCase you just use the raw string
Code:
public class tester{
public static void main(String[] args){
String s="Roar";
int total=0;
s.toLowerCase(); ///////////////you did not use me
for(int j=0; j<=s.length()-1;j++)
{if (s.charAt(j)=='r')
total++;
System.out.println(total);
}
}
}
you use it in your print statement if you want to show s in lowercase:
Code:
String t = s.toLowerCase();
System.out.println(t);
now it should print all lowercase
Re: Beginner Loop Question
ok, thanks so much for pointing that out! So basically my original statement did nothing. Thank you for clearing that up
Re: Beginner Loop Question
did we help you? Please press the add the reputation
Re: Beginner Loop Question
Quote:
Originally Posted by
RichersooN
did we help you? Please press the add the reputation
No, you didn't help the op; Strings are immutable and a simple s.toLowerCase() doesn't do anything; please check your facts before you post a (non) solution and begging for rep points is sort of childish too.
Jos