0

so this is what the output should be:
A b C d E f G h I j K l M n O p Q r S t U v W x Y z

heres what ive done so far

class za
{
public static void main(String[]args)
{
String x="abcdefghijklmnopqrstuvwxyz";
int ctr;
for(ctr=0;ctr<=x.length()-1;ctr++)
{
if(ctr%2)
System.out.print(Character.toUpperCase(x.charAt(0)));
}
}
}

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by stultuske
0

replace
System.out.print(Character.toUpperCase(x.charAt(0)));
with
System.out.print(Character.toUpperCase(x.charAt(ctr)));

the way your code is now, you are always setting your first character (index = 0) to upper case.

0

ctr%2 gives a numerical value, not a boolean (true/false) what you need to get your if to work.

you'll have to compare it to 0 to see whether or not your index is even.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.