Write a program in java.io package to take a String as input then display first word all capital letters, second word all small letters, third word all capital letters and so on.
Example:
Enter a String
Asia is the largest continent
ASIA is THE largest CONTINENT
import java.util.*;
class App {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a String: ");
String words[] = in.nextLine().toLowerCase().split(" ");
for (int i = 0; i < words.length; i++) {
if (i % 2 == 0) {
System.out.print(words[i].toUpperCase() + " ");
} else {
System.out.print(words[i].toLowerCase() + " ");
}
}
in.close();
}
}
Comments
Leave a comment