Java程序计算余数和商数
使用nextInt()扫描器类的方法从用户读取除数和除数。Java中的运算符%和/用于计算余数和商数。
示例
public class ComputeQuotientandRemainder {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of the divisor:: ");
int divisor = sc.nextInt();
int divident = sc.nextInt();
int quotient = divident / divisor;
int remainder = divident % divisor;
System.out.println("商值:"+quotient);
System.out.println("剩余值:"+remainder);
}
}输出结果
Enter the value of the divisor:: 125 5 商值:0 剩余值:5
热门推荐
10 读书祝福语女生短句简短
11 感谢同事新婚祝福语简短
12 感谢教官文案祝福语简短
13 员工聚会蛋糕祝福语简短
14 元宵发客户祝福语简短
15 给团队信心祝福语简短
16 医美的祝福语大全简短
17 异国姻缘的祝福语简短
18 兄妹拍照祝福语简短的话