我不明白如何获取我的输入字符串并使用右对齐打印出来

时间:2016-05-21 21:46:19

标签: java

enter image description here我正在接受一个字符串输入并提示用户输入得分值,用户可以输入最多5个分数且不低于1.我不明白如何取出该字符串并打印它没有更多的逗号,它们是正确的对齐。

这是我到目前为止所做的:

//user inputs for number of students
    numStudents = UtilsKS.readInt("Enter number of students: ", false);                                

    //while loop for correct input of students
    while (numStudents <= 0 || numStudents > 12) { 
        System.out.print("ERROR: must be 1-12, ");

        numStudents = UtilsKS.readInt("Enter number of students: ", false);
    }

    // user input for student score using a for loop
    for (int i = 0; i < numStudents; i++) {
        stuScores = UtilsKS.readString("Enter comma-separated test score for student " + (i+1) + ": ", false);

    }

    //initializing testscore to = what scores are inputed per student
    for (int t=0; t<numStudents; t++) {
        testScores[t] = stuScores;
    }    

    // setting up turning string into separate arrays and trimming them
    array1 = stuScores.split(",");

    for (int i=0; i<array1.length; i++) {
        score[i] = Integer.parseInt(array1[i].trim());
    }

    //outputs
    System.out.println( String.format("%10s", header)); 
    System.out.println( String.format("%10.2f", score));

我的主要问题是如何获取输入并正确格式化以进行打印?

0 个答案:

没有答案