Java 中 怎么使得 一个数除以另一个数 小于1的 让除得的数=1 多了就加1

来源:百度知道 编辑:UC知道 时间:2024/09/28 15:18:08
就比如说 7/10=0.7
不足1 让除得的数=1
10/10=1

15/10=1.5
有余数的 让除得的数+1 就是说 7/10 = 1
10/10 =1
1.5/10= 2

怎么 写?

不知道 有没看懂。。
自己写了一个

public class Test {

/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根

int i=45;
int k=20;
int result=i/k;
if((i%k)!=0)
{
result=result+1;
}
System.out.print(result);
}

}

public class Demo {

public void math(int a, int b) {
int c;
if (a%b==0) {
c=a/b;
System.out.print("a/b="+c);
}
else {
c=a/b+1;
System.out.print("a/b="+c);
}
}

public static void main(String[] args) {
Demo demo = new Demo();
demo.math(31, 10);
}

}

//demo.math(31, 10)为31/10,结果是4,lz可自己改数字测试

public int myDivide(double a,double b)//a是被除数,b是除数
{
int result=a/b;
if(result<1)
result=1;
else if(result>1)
{
int temp=(int)result;
result=temp+1;
}
return result;
}

你写的看不懂

int a=10;
int b=3;
int c=a/b;
if (c-1>0)
c+=1;
if (c-1<0)
c=1;