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 放假假期祝福语简短精辟