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
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();
}
}
Comments
Leave a comment