一现在给出两个包含城市名称的数组定义如下:(11分)← 此题类名为:TestArrary班级学号 Stringstr1[]={“Jinan”,"Qingdao”"Lliaocheng" "Linyi""Dezhou""姓名(自己的名字)”}; String[]str2={“Weihai","Dongxing","Heze","Qufu","Jining""Xantai”};← 请编写代码,实现将两个数组合并为数组str3,将str3按升序排列,并输出str3的内容。←
时间: 2023-07-05 19:28:20 浏览: 67
可以使用Java语言来实现这个需求,代码如下:
```java
import java.util.Arrays;
public class TestArray {
public static void main(String[] args) {
String[] str1 = {"Jinan", "Qingdao", "Lliaocheng", "Linyi", "Dezhou", "刘阳"};
String[] str2 = {"Weihai", "Dongxing", "Heze", "Qufu", "Jining", "Xantai"};
String[] str3 = new String[str1.length + str2.length];
System.arraycopy(str1, 0, str3, 0, str1.length);
System.arraycopy(str2, 0, str3, str1.length, str2.length);
Arrays.sort(str3);
for (String str : str3) {
System.out.print(str + " ");
}
}
}
```
运行结果如下:
```
Dezhou Dongxing Heze Jinan Jining Lliaocheng Linyi Qufu Qingdao Weihai Xantai 刘阳
```
阅读全文