0
static void sort (Textbook [ ] info, int numEntries)
{
    long tempIsbn = 0;
    String tempTitle = "";
    String tempAuthor = "";

    for (int i = 0; i < numEntries; i++) //sorts the array
    {
        int minPos = i;
        for (int j = i + 1; j < numEntries; j++)
        {
            if ( info [minPos].getIsbn() > info [j].getIsbn())
            {
                minPos = j;
            } //end if
            if (i < minPos)
            {
                tempIsbn = info [i].getIsbn();
                info [i].getIsbn() = info [minPos].getIsbn();
                info [minPos].getIsbn() = tempIsbn;

                tempTitle = info [i].getTitle();
                info [i].getTitle() = info [minPos].getTitle();
                info [minPos].getTitle() = tempTitle;

                tempAuthor = info [i].getAuthor();
                info [i].getAuthor() = info [minPos].getAuthor();
                info [minPos].getAuthor() = tempAuthor;

            } //end if

        } //end for
    } //end for
} //end sort

我正在尝试对数据库进行排序,当我尝试将第一个值与第二个值进行比较时出现错误。据我了解,这info [i].getAuthor();是对对象类的调用,但它不应该返回一个值吗?我想我想知道为什么我会收到这些错误,因为它应该比较两个数字?

这是我的对象类的代码。

    public long getIsbn ( )
{
            return this.isbn;
}

    public String getTitle ( )
{
    return this.title;
}

public String getAuthor ( )
{
    return this.author;
}

这些是我遇到的一些错误。

    TextbookTracker.java:156: unexpected type
    required: variable
    found   : value
        info [i].getIsbn() = Long.parseLong (isbnInput);
                        ^
    TextbookTracker.java:161: unexpected type
    required: variable
    found   : value
        info [i].getTitle() = titleInput;
                         ^
    TextbookTracker.java:166: unexpected type
    required: variable
    found   : value
        info [i].getAuthor() = authorInput;
                          ^
    TextbookTracker.java:264: unexpected type
    required: variable
    found   : value
                info [i].getIsbn() = info [minPos].getIsbn();
                                ^
    TextbookTracker.java:265: unexpected type
    required: variable
    found   : value
                info [minPos].getIsbn() = tempIsbn;
                                     ^
    TextbookTracker.java:268: unexpected type
    required: variable
    found   : value
                info [i].getTitle() = info [minPos].getTitle();
                                 ^
    TextbookTracker.java:269: unexpected type
    required: variable
    found   : value
                info [minPos].getTitle() = tempTitle;
                                      ^
    TextbookTracker.java:272: unexpected type
    required: variable
    found   : value
                info [i].getAuthor() = info [minPos].getAuthor();
                                  ^
    TextbookTracker.java:273: unexpected type
    required: variable
    found   : value
                info [minPos].getAuthor() = tempAuthor;
                                       ^
    9 errors
4

1 回答 1

2
 TextbookTracker.java:156: unexpected type
 required: variable
 found   : value
    info [i].getIsbn() = Long.parseLong (isbnInput);

如何将值分配给值?在赋值运算符的左侧,您需要一个变量,而这里是一个返回值的方法调用

于 2013-05-10T04:46:10.823 回答