4-3 String_char

posted Feb 8, 2014, 6:03 AM by Dlovan ismail   [ updated Feb 8, 2014, 2:11 PM by Karwan Jacksi ]
/*
write a program in Java that will accept a string/word then print every letter of that word on a new line.
For example, the machine accepts ZIP then outputs:
Z
I
P
*/

package string_char;
import java.util.Scanner;

public class String_char
{
    public static void main(String[] args) 
    {
            System.out.print("Please enter your words : ");

            // Create a Scanner object for keyboard input.
            Scanner scan = new Scanner(System.in);

            //for storing a value you entered from keyboard.
            String word = scan.next();

            int i=0;

            while(i<word.length())
            {
                System.out.println(word.charAt(i));
                i++;
            }

    }   
}

ċ
Sting_char.java
(1k)
Karwan Jacksi,
Feb 8, 2014, 6:05 AM
Comments