Example:
package javaapplication;
import java.util.Scanner;
/**
*
* @author Rathorji
*/
public class JavaApplication {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int total, score;
int percentage;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the total amount of score: ");
total = sc.nextInt();
System.out.println("Enter the score obtained: ");
score = sc.nextInt();
percentage = (score * 100 / total);
System.out.println("The percentage is = " + percentage + "%");
}
}
output:
run:
Enter the total amount of score: 400 Enter the score obtained: 200 The percentage is = 50% |