Alternate letters in uppercase

 Alternate letters in uppercase

A str‌ing S (only alphabets) is passed as input. The printed output should contain alphabets in odd positions in each word in uppercase and alphabets in even positions in each word in lowercase.

PROGRAM IN JAVA:
********************************************************************************

import java.util.*;
public class Hello {

    public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
String[] s1=s.split(" ");
for(String x:s1)
{
    int i=0;
    for(Character ch:x.toCharArray())
    {
        if(i%2==0)
            System.out.print(Character.toUpperCase(ch));
        else
            System.out.print(Character.toLowerCase(ch));
        i++;
    }
    System.out.print(" ");
}
}

}

*****************************************************************************

Comments

Popular Posts