int a=45;
int b =102;
我要算出a是b的百分之几,后面带%号,怎么算,高分送出

解决方案 »

  1.   

    int a=45;
    int b =102;
    double c = (double)a/b*100;
    String str = c + "%";
    System.out.println(str);
      

  2.   

    lanseqingxu(蓝色情绪) ::不行呀,为什么结果是Infinity%  ??????
      

  3.   

    我的代码在jdk1.5下编译无误,而明月的输出结果为0
    大家用的jdk版本是什么?
      

  4.   

    楼上的已经是正确的了,只是补充一下,
    int a=45;
    int b=102;
    double d=((double)a/b)*100;
    NumberFormat nf= new DecimalFormat("#.00");//可以定义数据的格式为保留两位小数
    System.out.println(nf.format(d)+"%");
      

  5.   

    绝对可以,这么简单的东西啊!!!public class ss {
        public static void main(String[] args){
            int a=45;
    int b =102;
    double c = (double)a/b*100;
    String str = c + "%";
    System.out.println(str);
        }}
      

  6.   

    import java.text.*;public class ss {
        public static void main(String[] args){
            int a=45;
            int b =102;
            double c = (double)a/b*100;
            double d = ((double)a/b)*100;
            String str = "c=" + c + "%";
            NumberFormat nf= new DecimalFormat( "#.00" );//可以定义数据的格式为保留两位小数
            System.out.println( str );
            System.out.println( "d=" + nf.format(d) + "%" );

        }}d=44.12%
    c=44.11764705882353%
      

  7.   

    lanseqingxu(蓝色情绪) ::
    可以通过的。你是什么提示错误啊