日期:2014-05-20  浏览次数:20620 次

一道算法题。。。高手请指教
用 "+,- "运算符计算整数x除以整数y的商和余数    
怎么做啊。。高手请指教哈。。。

------解决方案--------------------
int count=0;
int yushu=x;
for(;yushu> y;count++)
yushu-=y;
商是:count余数是yushu
------解决方案--------------------
循环减法 计算次数
public class Test {

public static void main(String[] args) {
int x = 10, y = 1;
int quotient = 0, residue = 0;
while (x > = y) {
x -= y;
quotient += 1;
}
residue = x;

System.out.println( "The Quotient is: " + quotient);
System.out.println( "The Residue is: " + residue);
}

}