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

Question #298026

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


1
Expert's answer
2022-02-15T12:20: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 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();
	}
}

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