Write a program to take a string as input then display the words along with position of each character its below but don't take a white blank space as a separate character.
Example:
Enter a String
Hello World RUN
12345 67890 123
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();
		int counter = 1;
		for (int i = 0; i < inputString.length(); i++) {
			if (inputString.charAt(i) != ' ') {
				System.out.print(counter);
				counter++;
			}else {
				System.out.print(" ");
			}
		}
		in.close();
	}
}
Comments