導航:首頁 > 編程知識 > java編程怎麼輸出百分數

java編程怎麼輸出百分數

發布時間:2023-02-25 05:39:44

java怎麼計算百分比

JAVA計算百分比參考以下操作:

intnum1=7;

intnum2=9;

//創建一個數值格式化對象

NumberFormatnumberFormat=NumberFormat.getInstance();

//設置精確到小數點後2位

numberFormat.setMaximumFractionDigits(2);

Stringresult=numberFormat.format((float)num1/(float)num2*100);

System.out.println("num1和num2的百分比為:"+result+"%");

Ⅱ java的百分數輸出問題

import java.text.NumberFormat;
/**
*
* @author Administrator
*/
public class Question8 {

/** Creates a new instance of Question8 */
public Question8() {
}
public static void main(String[] args){
NumberFormat nf = NumberFormat.getPercentInstance();
nf.setMaximumIntegerDigits(3); // 設置數的整數部分所允許的最大位數
nf.setMaximumFractionDigits(2);// 設置數的小數部分所允許的最大位數
double d = 0.2;
System.out.println(nf.format(d));
}

}

Ⅲ java 怎麼把一個數變成百分比

importjava.util.Scanner;

publicclassPercentage{
publicstaticvoidmain(String[]args){
Scannersc=newScanner(System.in);
System.out.println("pleaseenteranumber:");
doublex=sc.nextDouble();
doublex2=x*100;
System.out.println(x2+"%");
}

}

Ⅳ java百分比的輸入輸出

你要確定你需要輸幾個數字?

可以定義一個數組接受

然後再去計算

List<Integer>arr=newArrayList<Integer>();
Scanners=newScanner(Sysyem.in);
inta=s.nextInt;//如果輸入別的你自己判斷
if(a<0){
System.out.println("你輸入的數字小於0,請重新輸入");
}
arr.add(a);
intsum=0;
for(inti=0;i<arr.size();i++){
sum+=list.get(i);
}
for(inti=0;i<arr.size();i++){
System.out.println(list.get(i)+"的百分比是:"+list.get(i)/sum);
}
沒有測試有錯在提問吧
閱讀全文

與java編程怎麼輸出百分數相關的資料

熱點內容
編程怎麼設置一分鍾開燈 瀏覽:754
如何把桌面文件發送到自己郵箱 瀏覽:498
校園網站怎麼看選修的課 瀏覽:59
大數據專業哪個最好 瀏覽:467
一個文件內容替換另一個文件 瀏覽:288
ios8最好的版本 瀏覽:400
錄屏決定文件大小的是什麼 瀏覽:322
數據用不了是哪裡壞掉了 瀏覽:310
百度網盤文件傳輸格式 瀏覽:455
蘋果系統txt文件 瀏覽:629
家裝網站怎麼設計 瀏覽:202
adc指令微程序 瀏覽:487
名片模板word 瀏覽:635
怎麼把文件夾上鎖 瀏覽:331
我不會英語怎麼編程 瀏覽:895
c盤和文件大小 瀏覽:63
maya工具架怎麼調出來 瀏覽:191
文件系統壞了怎麼辦 瀏覽:261
小公司網路布線 瀏覽:515
怎麼用二維碼編程 瀏覽:341

友情鏈接