Skip to main content

Java Sample: While loop with String Buffer


import java.io.*;
public class whilechk
{
    public static void main(String args[])
    {
        StringBuffer string=new StringBuffer();
        char c;
        System.out.println("\nEnter a String");
        try
        {
            while((c=(char)System.in.read())!='\n')
            {
                string.append(c);
            }
        }
        catch (Exception e)
        {
               System.out.println(e.getMessage());
        }
        System.out.println("\nYou Have Entered ... " + string);
    }
}

Comments