Answer to Question #298736 in Java | JSP | JSF for Woder

Question #298736

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


1
Expert's answer
2022-02-20T10:00:04-0500


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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS