Write a program to input a string and print each character of the string in different line.

 THE FOLLOWING PROGRAM SEGMENT SHOWS HOW TO EXTRACT EACH CHARACTER FROM THE STRING AND PRINT IT:

import java.util.*;

class string

{

    public static void main (String args[])

    {

        Scanner ob = new Scanner (System.in);

        System.out.println("Enter a string");

        String s = ob.nextLine();

        for(int i =0; i<s.length(); i++)

        {

            char ch = s.charAt(i);

            System.out.println("Characters of the string are = "+ch+ "\t");

        }

        }

    }

OUTPUT:

Enter a string

askris

Characters of the string are = a

Characters of the string are = s

Characters of the string are = k

Characters of the string are = r

Characters of the string are = i

Characters of the string are = s

The above program CODE is compiled and is without any error.

Hope you guys found it helpful.

Please share it with your friends and comment down in the comment section below.

Follow https://askrisfor.blogspot.com/ for more such updates.

Visit us again.

Thank you!!

Comments

Popular Posts