Computer Science, asked by Gucock, 20 days ago

Write a program in Java to accept a percentage and display it in ratio form

Answers

Answered by raotd
0

Answer:

Percent means percent (hundreds), i.e., a ratio of the parts out of 100. The symbol of a percent is %. We generally count the percentage of marks obtained, return on investment etc. The percentage can go beyond 100% also.

For Example, assuming that we have total and a part. So we say what part is what percent of total and should be calculated as −

percentage = ( part / total ) × 100

Algorithm

1. Collect values for part and total

2. Apply formula { percentage = ( part / total ) × 100 }

3. Display percentage

Example

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);

}

}

Output

Enter your marks ::

500

Enter total marks ::

600

Percentage ::83.33333

Similar questions