如何实现java 两数相除得到百分数 比如25.12%

来源:百度知道 编辑:UC知道 时间:2024/05/12 20:46:36
急用,谢谢各位了!

float a = 4.35;
float b = 10.16;

System.out.println(a * 100 / b + "%");

浮点型相除再除以100在加上‘%’

NumberFormat类里面有个getPercentInstance()的方法。

public class exercise1 {
public static void main(String[] args) {
int leng = 5900;
int width = 2350;
int height = 2393;
int l = 120;
int w = 130;
int h = 333;
int ll = leng/l;//49
int ww = width/w;//18
int hh = height/h;//7
int sum = (ll)*(ww)*(hh);//5145
int lwh = l*w*h;
double a=lwh/leng;
double b=sum/width;
double per = a*b*100/height;
System.out.println(per + "%");
}
}