OneCompiler

Write a java program that uses do … while loop to read a single word from the keyboard and output it vertically.

Write a java program that uses do … while loop to read a single word from the keyboard and output it
vertically.

1 Answer

5 years ago by
import java.util.*;

public class HelloWorld {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        System.out.println("Enter a string");
        String str = s.nextLine();
        for (int i=0; i<str.length(); i++)
        System.out.println(str.charAt(i));
    }
}

Check output here

5 years ago by Divya