Answer to Question #298409 in Java | JSP | JSF for Mesew

Question #298409

Write a program to take a String name as input then display the signature using substring().

Example:

Enter a String

Chandra Bahadur Dangi Ailen Coq

C. Bahadur D. Ailen C.


1
Expert's answer
2022-02-16T10:21:23-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().split(" ");
		for (int i = 0; i < words.length; i++) {
			if (i % 2 == 0) {
				System.out.print(words[i].substring(0, 1) + ". ");
			} else {
				System.out.print(words[i] + " ");
			}
		}


		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