codescracker


java

Java Program to Copy String



« Previous Program Next Program »


Copy String

To copy string in Java Programming, you have to ask to the user to enter the string to make copy to another variable say strCopy and display this variable which is the copied value of the given string as shown in the following program.

Java Programming Code to Copy String

Following Java Program ask the user to enter a string to copy it into another string, then display the copied string on the screen :

/* Java Program Example - Copy String */
		
import java.util.Scanner;

public class JavaProgram
{
   public static void main(String args[])
   {
      String strOrig;
      Scanner scan = new Scanner(System.in);
 
      System.out.print("Enter a String : ");
      strOrig = scan.nextLine();
      
      System.out.print("Copying String...\n");
      
      StringBuffer strCopy = new StringBuffer(strOrig);
      
      System.out.print("String Copied Successfully..!!\n");      
      System.out.print("The Copied String is " + strCopy);
   }
}

When the above Java Program is compile and executed, it will produce the following output:

Java Program copy string

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test