String - copy one string into another Given a string S, write a program to copy the given string into another string. Input: Hello World where: First-line represents the input string Output: Hello World Assumptions: Length of the string S can be 0 to 10000
时间: 2023-11-27 18:51:40 浏览: 31
Here's an example program in Java that copies a given string into another string:
```
import java.util.Scanner;
public class StringCopyExample {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String inputString = scanner.nextLine();
String copiedString = inputString; // copy the string
System.out.println(copiedString);
}
}
```
In this program, we use the `Scanner` class to read the input string from the user. We then copy the input string into a new string variable called `copiedString` using the assignment operator `=`. Finally, we print the copied string using the `System.out.println()` method.
This program assumes that the length of the input string can be between 0 and 10000 characters.