Java code for buffer operation...!!!

Java code for buffer operation...!!!

Implement a buffer operation using character array, storing last 100 characters inserted by user. Make method to get and retrieve???

View Answers

June 18, 2012 at 5:24 PM

The given code accepts the characters from the user and stored into character array. Then it stores the last 100 character into the StringBuffer and displayed on console.

import java.util.*;

class BufferOperation 
{
    public static void main(String[] args) 
    {
        StringBuffer buffer=new StringBuffer();
        Scanner input=new Scanner(System.in);
        char chars[]=new char[150];
        for(int i=0;i<chars.length;i++){
        System.out.print("Enter character: ");
        char ch= input.next().charAt(0);
        chars[i]=ch;
        }
        for(int i=chars.length-100;i<chars.length;i++){
            buffer.append(chars[i]);
            buffer.append("\n");
        }
        System.out.println(buffer.toString());
    }
}

June 18, 2012 at 5:30 PM

thanx buddy


June 18, 2012 at 6:17 PM

this code is not work properly......plz check it and explain me.....plz


April 15, 2013 at 12:46 PM

kindly put solution of this..given solution is not working









Related Tutorials/Questions & Answers:

Ads