我是 java 和数组列表的新手。我应该排序填充一个充满随机整数的数组,然后如果有一个运行(一行中相同数字的倍数),则在该运行周围放置()。所以如果随机列表是:
2 3 4 5 5 5 5 6 7 7 9
2 3 4 (5 5 5 5) 6 (7 7) 9
这是我到目前为止所拥有的:
import java.util.*;
class Run {
public static void main (String [] args){
Scanner m = new Scanner(System.in);
System.out.print("Enter length wanted: ");
int len = m.nextInt();
System.out.print("Enter max number wanted: ");
int max = m.nextInt();
max = max -1;
int[] x = new int[len];
ArrayList<String> y = new ArrayList<String>();
//Filling x with random numbers
for(int i = 0; i<len; i++){
x[i] = ((int)(Math.random()*max)+1);
}
System.out.println("Orginal Array: " + Arrays.toString(x));
for(int i = 0; i<=len-1; i++){
if(x[i] == x[i++]){ //I just don't know how I am exactly supposed to sort this
}else{
}
}
//Array List with ()
System.out.println("Runs labeled Array: " + y);
}
}