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
Don't use array and split function
import java.util.*;
class App {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a String: ");
String inputString = in.nextLine().toLowerCase();
boolean isLowerCase=false;
for (int i = 0; i < inputString.length(); i++) {
if (isLowerCase) {
System.out.print(inputString.toLowerCase().charAt(i));
} else {
System.out.print(inputString.toUpperCase().charAt(i));
}
if (inputString.charAt(i) == ' ') {
isLowerCase=!isLowerCase;
}
}
in.close();
}
}
Comments
Leave a comment