Answer to Question #299174 in Java | JSP | JSF for Senew

Question #299174

Write a program to take a String name as input without using array and display the name in the format that even words will be first letter only.

Enter a String

Hun leij cenr xanf ewasn

Hun l. cenr x. eswasn

Hint: Use trim(), indexOf(), lastIndexOf(), charAt(), substring() if necessary.

Don't use Character class and split


1
Expert's answer
2022-02-21T15:03:31-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();
		boolean isOneLtter = false;
		int c = 0;
		for (int i = 0; i < inputString.length(); i++) {
			if (isOneLtter) {
				if (c == 0) {
					System.out.print(inputString.charAt(i) + ". ");
				}
				c++;
			} else {
				System.out.print(inputString.charAt(i));
			}
			if (inputString.charAt(i) == ' ') {
				isOneLtter = !isOneLtter;
				c = 0;
			}
		}


		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