我的目标是生成从 0 到 100 的随机数并将它们添加到链表对象中,然后对元素进行排序。
到目前为止,这是我的代码。当我想显示已排序的元素时遇到了问题。
我得到的错误:线程“main”中的异常 java.util.IllegalFormatConversionException: d != java.util.Arrays$ArrayList
有人可以解决这个问题吗?谢谢你
package com.LinkedLists;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.LinkedList;
import java.util.Random;
import java.util.Set;
public class InsertRandomElements {
public static void main(String[] args) {
// Create a random number object from 0 to 100.
// Create an array object.
Random r = new Random();
int[] random = new int[100];
// Insert random numbers into the array
for (int i = 0; i < random.length; i++) {
random[i] = r.nextInt(100) + 1;
}
// Printing out the unsorted array
for (int i = 0; i < random.length; i++) {
System.out.println(random[i]);
}
List<int[]> randomList = Arrays.asList(random);
// Call the method in here.
sortElements(randomList);
}
// Sort the elements
private static void sortElements(Collection<int[]> values) {
Set<int[]> set = new HashSet<int[]>(values);
for (int[] is : set) {
System.out.printf("Sorted Elements: %d ", values);
}
System.out.println();
}
// Calculate Sum of the elements
// Calculate floating point average of the elements.
}