대괄호와 쉼표로 프로그램에서 배열을 인쇄하려고합니다. 여기 내 코드는 다음과 같습니다 :괄호와 쉼표로 배열 출력을 Java로 표시 하시겠습니까?
public static void main(String[] args) {
int[] arrayIntList = new int[10]; // Starting the array with the specified length
int sum = 0; // Defining the sum as 0 for now
// Using the for loop to generate the 10 random numbers from 100 to 200, inclusive.
for(int nums1 = 0; nums1 < arrayIntList.length; nums1++) {
arrayIntList[nums1] = (int)(100 + Math.random()*101);
}
Arrays.sort(arrayIntList); // Sorting the array list
System.out.print("[");
for(int i = 0; i < arrayIntList.length; i++) { // Printing the array
System.out.print(arrayIntList[i] + " ");
}
System.out.print("]");
int[] arrayC = CalcArray(arrayIntList); // Sending the array to the method
System.out.println("");
for(int doubles : arrayC) {
System.out.print(doubles + " "); // Printing the output from the second method and calculating the sum
sum = sum + doubles;
}
System.out.printf("%nThe total is %,d", sum); // Printing the sum
}
private static int[] CalcArray(int[] nums) {
for(int nums2 = 0; nums2 < nums.length; nums2++) { // Doubling the original array
nums[nums2] *= 2;
}
return nums; // Returning the doubles numbers
}
내가 찾는 형식은 [1, 2, 3, 4, 5, 6]과 같습니다. 누군가가 나에게 약간의 조언을 줄 수 있다면 그것은 좋을 것입니다. 감사합니다.
첫 번째 downvote, 만세! – AvenNova
지금 무엇을 얻고 있습니까?문제에 대한 자세한 정보를 입력해야합니다 – techspider