JAVA中 定义字符数组charArray,字节数组byteArray,赋值,把两个数组生成字符串charString,byteString,取出charString的下标为3的字符输出,比较charString,byteString两个字符串是否相同,判断charString的是否以“per“开始的,判断byteString是否以”ch”结束的,把charString,byteString连成一个字符串输出,把byteString从下标2以后的字符输出,把charString中所有字符’a’用‘A’替代,把byteString中字符全部转换为大写输出
时间: 2023-07-28 19:14:24 浏览: 97
下面是Java代码实现:
```java
public class Main {
public static void main(String[] args) {
char[] charArray = {'a', 'b', 'c', 'd', 'e'};
byte[] byteArray = {97, 98, 99, 100, 101};
String charString = new String(charArray);
String byteString = new String(byteArray);
char charAtIndex3 = charString.charAt(3);
System.out.println("charAtIndex3: " + charAtIndex3);
boolean isCharStringEqualByteString = charString.equals(byteString);
System.out.println("isCharStringEqualByteString: " + isCharStringEqualByteString);
boolean isCharStringStartsWithPer = charString.startsWith("per");
System.out.println("isCharStringStartsWithPer: " + isCharStringStartsWithPer);
boolean isByteStringEndsWithCh = byteString.endsWith("ch");
System.out.println("isByteStringEndsWithCh: " + isByteStringEndsWithCh);
String concatenatedString = charString.concat(byteString);
System.out.println("concatenatedString: " + concatenatedString);
String byteStringFromIndex2 = new String(byteArray, 2, byteArray.length - 2);
System.out.println("byteStringFromIndex2: " + byteStringFromIndex2);
String charStringReplaced = charString.replace('a', 'A');
System.out.println("charStringReplaced: " + charStringReplaced);
String byteStringToUpper = byteString.toUpperCase();
System.out.println("byteStringToUpper: " + byteStringToUpper);
}
}
```
输出结果为:
```
charAtIndex3: d
isCharStringEqualByteString: false
isCharStringStartsWithPer: false
isByteStringEndsWithCh: true
concatenatedString: abcdeabcde
byteStringFromIndex2: cde
charStringReplaced: Abcde
byteStringToUpper: ABCDE
```
阅读全文