Answer to Question #297584 in Java | JSP | JSF for Initier

Question #297584

Write a program to take a String as input then display the first letter of each word.

Example:

Enter a String

JAPAN is Best

JiB


1
Expert's answer
2022-02-14T12:04:48-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 string = in.nextLine();
		int length = string.length();
		System.out.print(string.charAt(0));
		for (int i = 0; i < length; i++) {
			if (string.charAt(i) == ' ') {
				System.out.print(string.charAt(i + 1));
			}
		}


		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