gpt4 book ai didi

JAVA:如果有余数打印一行代码,我该如何编写if语句?

转载 作者:行者123 更新时间:2023-12-01 20:52:37 26 4
gpt4 key购买 nike

问题出在底部。我做了一行注释来指示该区域。我想我需要在那里添加某种条件?没有线索。感谢您的时间。

    import java.util.Scanner;

public class how {

public static void main(String[] args) {
Scanner myScanner = new Scanner(System.in);
int gumBalls;
int kids;
int gpk;

System.out.println("How many gum balls? How many kids?");

gumBalls = myScanner.nextInt();
kids = myScanner.nextInt();

gpk = gumBalls / kids;

System.out.print("each person gets ");
System.out.print(gpk);
System.out.print(" gumballs");


//this is where I am stuck
if (gpk % > 1) {
System.out.println("Better throw those extras away..");
}
}

}

最佳答案

if (gumBalls % kids  != 0) {
System.out.println("Better throw those extras away..");
}

关于JAVA:如果有余数打印一行代码,我该如何编写if语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42989004/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com