Answer to Question #299495 in Java | JSP | JSF for Ener

Question #299495

Write a program to take a String as input then display the words in spaced format.

Example:

Enter a String

Asia is the largest continent

Asia

\t is

\t \t the

\t \t \t largest

\t \t \t \t continent


1
Expert's answer
2022-02-18T14:11:07-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(" ");
		String tab = "";


		for (int i = 0; i < words.length; i++) {
			System.out.println(tab + words[i]);
			tab += "\t";
		}


		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