while循环中的最后一行在第二个循环的每次迭代后打印。如何在收到给定命令后打印一次? package toto.com; 导入java.util.Scanner; 公共类编校者{ 公共静态void main(字符串[]args){ 扫描仪=新的扫描仪(System.in); String=scanner.nextLine(); 双赢=0; 双失=0; 双插座=0; //输入 //芭蕾舞演员 //3 //87 //63 //56 //65 //75 //64 //鲨鱼 //4 //64 //76 //65 //86 //68 //99 //45 //78 //比赛结束 //输出在底部 而(!锦标赛.equals(“锦标赛结束”)){ int matches=Integer.parseInt(scanner.nextLine()); 插座+=火柴; 对于(int i=0;i点2){ 韩元++; System.out.printf(“%n比赛%s的名称%d:以%d点获胜。”,i,比赛,点1-点2); }否则{ 丢失的++; System.out.printf(“%n比赛%s的名称%d:因%d点而丢失。”,i,比赛,点2-点1); } } System.out.printf(“%n%.2f%%匹配赢%n”+ “%.2f%%matches lost”、(won/receptor)*100、(lost/receptor)*100);//就我而言,在循环外使用if语句打印它似乎不起作用,因为其中的条件始终为真。 锦标赛=scanner.nextLine(); } } } //期望输出 //锦标赛芭蕾选手第一场:以24分获胜。 //芭蕾锦标赛第二场:以9分输掉。 //锦标赛芭蕾选手第三场:以11分获胜。 //鲨鱼锦标赛第一场:以12分输掉。 //鲨鱼锦标赛第二场:以21分输掉。 //鲨鱼锦标赛第三场:以31分输掉。 //鲨鱼锦标赛第四场:以33分输掉。 //28.57%的比赛获胜 //71.43%的比赛失败

while循环中的最后一行在第二个循环的每次迭代后打印。如何在收到给定命令后打印一次? package toto.com; 导入java.util.Scanner; 公共类编校者{ 公共静态void main(字符串[]args){ 扫描仪=新的扫描仪(System.in); String=scanner.nextLine(); 双赢=0; 双失=0; 双插座=0; //输入 //芭蕾舞演员 //3 //87 //63 //56 //65 //75 //64 //鲨鱼 //4 //64 //76 //65 //86 //68 //99 //45 //78 //比赛结束 //输出在底部 而(!锦标赛.equals(“锦标赛结束”)){ int matches=Integer.parseInt(scanner.nextLine()); 插座+=火柴; 对于(int i=0;i点2){ 韩元++; System.out.printf(“%n比赛%s的名称%d:以%d点获胜。”,i,比赛,点1-点2); }否则{ 丢失的++; System.out.printf(“%n比赛%s的名称%d:因%d点而丢失。”,i,比赛,点2-点1); } } System.out.printf(“%n%.2f%%匹配赢%n”+ “%.2f%%matches lost”、(won/receptor)*100、(lost/receptor)*100);//就我而言,在循环外使用if语句打印它似乎不起作用,因为其中的条件始终为真。 锦标赛=scanner.nextLine(); } } } //期望输出 //锦标赛芭蕾选手第一场:以24分获胜。 //芭蕾锦标赛第二场:以9分输掉。 //锦标赛芭蕾选手第三场:以11分获胜。 //鲨鱼锦标赛第一场:以12分输掉。 //鲨鱼锦标赛第二场:以21分输掉。 //鲨鱼锦标赛第三场:以31分输掉。 //鲨鱼锦标赛第四场:以33分输掉。 //28.57%的比赛获胜 //71.43%的比赛失败,java,loops,for-loop,while-loop,nested,Java,Loops,For Loop,While Loop,Nested,我把你的问题理解为询问如何在比赛结束后才打印输赢数字。要完成此操作,请在while循环后移动最后的printf语句。那么它只会在你的比赛结束后运行一次 package toto.com; import java.util.Scanner; public class redactor { public static void main(String[] args) { Scanner scanner = new Scanner(System.in);

我把你的问题理解为询问如何在比赛结束后才打印输赢数字。要完成此操作,请在while循环后移动最后的printf语句。那么它只会在你的比赛结束后运行一次

package toto.com;

import java.util.Scanner;

public class redactor {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);


        String tournament = scanner.nextLine();

        double won = 0;
        double lost = 0;
        double receptacle = 0;

        //Input
          //Ballers
          //3
          //87
          //63
          //56
          //65
          //75
          //64
          //Sharks
          //4
          //64
          //76
          //65
          //86
          //68
          //99
          //45
          //78
          //End of tournaments
          // the output is at the bottom
  


        while (!tournament.equals("End of tournaments")) {
            int matches = Integer.parseInt(scanner.nextLine());
            receptacle += matches;

            for (int i = 0; i < matches; i++) {//TODO redact of needed to 0 and <
                int points1 = Integer.parseInt(scanner.nextLine());
                int points2 = Integer.parseInt(scanner.nextLine());

                if (points1 > points2) {
                    won++;
                    System.out.printf("%nGame %d of tournament %s: win with %d points.", i, tournament, points1 - points2);
                } else {
                    lost++;
                    System.out.printf("%nGame %d of tournament %s: lost with %d points.", i, tournament, points2 - points1);
                }

            }


            System.out.printf("%n%.2f%% matches win%n" +
                    "%.2f%% matches lost", (won / receptacle) * 100, (lost / receptacle) * 100); // As far as I'm concerned printing it outside of the loop using if statement doesnt't seem to work because the condition within is always true. 
            tournament = scanner.nextLine();

        }
    }


}
   
   

   //Desired Output
    //Game 1 of tournament Ballers: win with 24 points.
    //Game 2 of tournament Ballers: lost with 9 points.
    //Game 3 of tournament Ballers: win with 11 points.
    //Game 1 of tournament Sharks: lost with 12 points.
    //Game 2 of tournament Sharks: lost with 21 points.
    //Game 3 of tournament Sharks: lost with 31 points.
    //Game 4 of tournament Sharks: lost with 33 points.
    //28.57% matches win
    //71.43% matches lost

它在for循环中打印统计数据,然后程序继续进行到结束。我更新了我的答案,使游戏统计数据和锦标赛赢/输统计数据之间的区别更加明确。你能确认我的答案中的输出符合你的期望吗?它是无效的。它不会像我上面提到的那样打印最终统计数据(锦标赛赢/输)。还有其他建议吗?这很奇怪,因为它会在我这边打印赢/输统计数据。您能否提供包含上述建议的代码的更新版本?
while (!tournament.equals("End of tournaments")) {
    int matches = Integer.parseInt(scanner.nextLine());
    receptacle += matches;

    for (int i = 0; i < matches; i++) {//TODO redact of needed to 0 and <
        int points1 = Integer.parseInt(scanner.nextLine());
        int points2 = Integer.parseInt(scanner.nextLine());

        if (points1 > points2) {
            won++;
            System.out.printf("%nGame %d of tournament %s: win with %d points.", i, tournament, points1 - points2);
        } else {
            lost++;
            System.out.printf("%nGame %d of tournament %s: lost with %d points.", i, tournament, points2 - points1);
        }

    }

    // Location of line to move from
    tournament = scanner.nextLine();

}
// Location of print statment to move to
System.out.printf("%n%.2f%% matches win%n" +
        "%.2f%% matches lost", (won / receptacle) * 100, (lost / receptacle) * 100); // As far as I'm concerned printing it outside of the loop using if statement doesnt't seem to work because the condition within is always true.
 
Game 0 of tournament Ballers: win with 24 points.
Game 1 of tournament Ballers: lost with 9 points.
Game 2 of tournament Ballers: win with 11 points.
Game 0 of tournament Sharks: lost with 12 points.
Game 1 of tournament Sharks: lost with 21 points.
Game 2 of tournament Sharks: lost with 41 points.
Game 3 of tournament Sharks: lost with 33 points.
28.57% matches win
71.43% matches lost