小编Edo*_*dot的帖子

程序的最后一点我无法工作.(构造)

这是我的程序的最后一个代码部分,我不能使它工作:

问题是当我打印出来时,程序使用words实例变量.

如何更改代码,以便我可以在下面的main方法中使用wordList?这是我必须在构造函数中更改的内容吗?

import java.util.Arrays;

public class Sentence {
private String[] words = {""}; // My private instance variable. 
//Supposed to hold  the words in wordList below.

public Sentence(String[] words){ // Constructor which I'm pretty sure is not 100% right
//Elements of array will be words of sentence. 
}

public String shortest() {
    String shortest = "";

    for (int i = 0; i < words.length; i++) {
        if(shortest.isEmpty())
            shortest = words[i];
        if (shortest.length() > words[i].length())
            shortest = words[i]; …
Run Code Online (Sandbox Code Playgroud)

java constructor instance-variables

1
推荐指数
1
解决办法
83
查看次数

标签 统计

constructor ×1

instance-variables ×1

java ×1