Ich versuche, das Array in meinem Programm mit Klammern und Kommas zu drucken. Hier ist mein Code:Anzeigen einer Array-Ausgabe mit Klammern und Kommas in 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
}
Das Format, das ich suche, ist etwas wie [1, 2, 3, 4, 5, 6]. Wenn jemand mir einige Hinweise geben könnte, dann wäre das großartig. Vielen Dank!
Erster Downvote, hurra! – AvenNova
was bekommst du jetzt?Sie müssen mehr Informationen zu dem Problem geben – techspider