Sunday, 6 January 2013

PROGRAM TO CONCATENATE STRING IN JAVA


import java.io.*;

class Concate

{

        public static void main ( String args [] )

        throws IOException

        {

                BufferedReader br = new BufferedReader ( new InputStreamReader ( System.in ) );

                System.out.print("\n\nEnter 1st String  :   ");

                String s1 = new String ( br.readLine() );

                System.out.print("\n\nEnter 2nd String  :   ");

                String s2 = new String ( br.readLine() );

                StringBuffer sb = new StringBuffer( concatenate ( s1 , s2 ) );

                System.out.println("\n\nStringBuffer      :   " + sb + "\n" );

        }

        public static String concatenate ( String s1 , String s2 )

        {

                return ( s1 + ' ' + s2 );

        }

}

No comments: