Discuss / Java / 作业,已验证。

作业,已验证。

Topic source

Nobody52297

#1 Created at ... [Delete] [Delete and Lock User]

import java.util.Arrays;

public class Main {

    public static void main(String[] args) {

        int[] scores = new int[] { 88, 77, 51, 66 };

        Score s = new Score(scores);

        s.printScores();

        scores[2] = 99;

        s.printScores();

    }

}

class Score {

    private String scores="[";

    public Score(int[] sc) {

        for(int i:sc) {

        scores =scores + i + ",";

        }

        scores = scores.substring(0, scores.length() -1);

        scores = scores + "]";

    }

    public void printScores() {

        System.out.println(scores);

    }

}


  • 1

Reply