gpt4 book ai didi

java - arraylist 给出 "cannot be resolved"和 "cannot be resolved to a type"错误(eclipse)

转载 作者:行者123 更新时间:2023-12-01 11:44:44 24 4
gpt4 key购买 nike

我正在编写一个选择排序程序,它还没有完成,所以有很多错误,但我首先要修复的是 eclipse 不断给我的错误:

thelist cannot be resolved to a type

再说一次,在程序的其余部分:

thelist cannot be resolved

我的程序如下所示:

import java.util.ArrayList;
public class SelectionSort {

public static void main(String[] args) {
final int N = Integer.parseInt(args[0]);
//populate list with number from 1 to N

// Create an ArrayList containing Integer type elements
ArrayList<Integer> thelist = new ArrayList();

//while loop to accept a new value from random generator

//call sort method
}

public static void sort(final thelist<Integer> list) {

// declare an int variable to hold value of index at which the element
// has the smallest value
int smaller = 0;
int b=0;

// declare an int variable to hold the smallest value for each iteration
// of the outer loop
int smallerindex = 0;

for(int a=1;a<thelist.size();a++){
/* find the index at which the element has smallest value */
// initialize variables
smaller = thelist.get(a-1);
smallerindex = a-1;

for(b=a;b<thelist.size();b++){
if(thelist.get(b)<smaller){
// update smallest
smaller = thelist.get(b);
smallerindex = b;
}
}
// do nothing if the curIndex has the smallest value
//Swap the smallest element with the first element of unsorted subarray
int temp = thelist.get(destIndex);
thelist.set(destIndex, thelist.get(sourceIndex));
thelist.set(sourceIndex, temp);

}
}

}

最佳答案

在您的排序方法中,您将列表作为参数列表的类型:

public static void sort(final thelist<Integer> list) {

将其更改为:

public static void sort(final ArrayList<Integer> list) {

然后在main方法中需要调用sort方法的时候,就这样调用:

//call sort method
sort(thelist);

这就是您拥有列表“thelist”并在您的方法中使用它的方式。

关于java - arraylist 给出 "cannot be resolved"和 "cannot be resolved to a type"错误(eclipse),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29244378/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com