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)));
}
}
}

Recommended Answers

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.

Jump to Post

All 3 Replies

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.

theres a mistake at if(ctr%2)

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.