我希望这个数组在被 main 方法调用时打印时不带括号。
public static void main(String[] args) {
int [] temps = {15, 43, 23, 20};
System.out.print(Arrays.toString(arrayIncrease(temps)));
}
public static int[] arrayIncrease (int[] array) {
int [] tempsUp = new int[array.length];
for (int i = 0; i < array.length; i++)
tempsUp[i] = array[i] + 10;
return tempsUp;
}
电流输出
[25, 53, 33, 30]
最佳答案
您可以使用 substring 来提取字符串中括号内的部分:
String output = Arrays.toString(arrayIncrease(temps);
System.out.print(output.substring(1, output.length() - 1);
关于java - 从数组中删除括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57649095/