百分数表示百分数(百),即百分数与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