Java程序计算百分比
百分数表示百分数(百),即百分数与100之比。百分数的符号为%。我们通常会计算获得的商标,投资回报率等百分比。该百分比也可以超过100%。
例如,假设我们有总数和一部分。所以我们说那一部分占总数的百分之几,应计算为-
percentage = ( part / total ) × 100
算法
1. Collect values for part and total
2. Apply formula { percentage = ( part / total ) × 100 }
3. Display percentage示例
import java.util.Scanner;
public class Percentage {
public static void main(String args[]){
float percentage;
float total_marks;
float scored;
Scanner sc = new Scanner(System.in);
System.out.println("Enter your marks ::");
scored = sc.nextFloat();
System.out.println("Enter total marks ::");
total_marks = sc.nextFloat();
percentage = (float)((scored / total_marks) * 100);
System.out.println("Percentage ::"+ percentage);
}
}输出结果
Enter your marks :: 500 Enter total marks :: 600 Percentage ::83.33333
热门推荐
10 毛笔哥哥结婚祝福语简短
11 向国庆送祝福语简短
12 建队节祝福语简短
13 朋友喜得外孙简短祝福语
14 小店营业的祝福语简短
15 餐饮生日祝福语简短独特
16 鲜花英语祝福语卡片简短
17 男朋友暴富祝福语简短
18 婶婶拜年祝福语大全简短