int po=3366;
 int len=242956;
 double bb;
 bb=po/len*100;
 Double percent = new Double(double);
 NumberFormat percentFormatter;
 String percentOut;
 percentFormatter = NumberFormat.getPercentInstance(new Locale("cn","CH"));
 percentOut = percentFormatter.format(percent);
 System.out.println(百分数是: + "   " + currentLocale.toString());

解决方案 »

  1.   

    int/int 缺省情况下是使用整型除法的,也就是说,3/5 = 0, 5/3 = 1, 8/3 = 2,看不明白的话就去看看什么叫取模。在这个问题里可以这样做:
    bb = ((float) po / len) * 100;
    这里用到了一个强制(显式)类型转换以及一个隐式类型转换。
      

  2.   

    写错了,应该这样子:
    bb = (int) ( ((float) po/len) * 100);
      

  3.   

    Sorry!上端程序写错了!你试试这个!
    int po=3366;
    int len=242956;
    double bb;
    bb=(double)po/len;
    Double percent = new Double(bb);
    NumberFormat percentFormatter;
    String percentOut;
    percentFormatter = NumberFormat.getPercentInstance();
    percentOut = percentFormatter.format(percent);
    System.out.println("百分数是: "+ percentOut);
      

  4.   

    类型转换问题:要求强制类型转换。这一点与c有区别。
    float bb=((float)(po*100))/242956;
    使用java.lang.Math.round()可四舍五入。
      

  5.   


    我想 pp616 想要的是百分比输出吧!上面的那段程序就能输出百分比!如果po=3;len=4;则上面那段程序的输出结果为 75%
      

  6.   

    int po=3366;
    int len=242956;
    long bb;
    Integer bm = new Integer(po);
    bb=bm.floatValue()/len*100;
      

  7.   

    TO:wxyxl(断肠人)
    好象你很悠闲啊?做什么工作?老板不管?
      

  8.   

    TO:wxyxl(断肠人)
    好象你很悠闲啊?做什么工作?老板不管?