Question: There are 3 questions for user to answer. For example: if user had made all answers correctly, the code will show that "You got 3 correct answer and your grade is 100%" 

```
    int x = ( int ) (20 * Math.random()) + 1;
    int y = ( int ) (20 * Math.random()) + 1;

    System.out.println(x + " + " + y + " : ");
    int sum = keyboard.nextInt();
    if (sum == (x+y)) {
        System.out.println("Correct!");
    }
    else {System.out.println("Wrong!");
    }

    System.out.println( x + " * " + y + " : ");
    int mult = keyboard.nextInt();
    if (mult == (x*y)) {
        System.out.println("Correct!");
    }
    else {System.out.println("Wrong!");

    }

    System.out.println(x + " - " + y + " : ");
    int minus = keyboard.nextInt();
    if (minus == (x-y)) {
        System.out.println("Correct!");
    }
    else {
        System.out.println("Wrong!");
    }

```

Answer: 
Firstly, declare some variables to work with for your test.

```
Integer userScore=0;
Integer totalScore=0;

```

The percentage is userScore/totalScore\*100. To add these up throughout the test, each of your questions should have something like this in them.

```
if (answerIsCorrect) {
    userScore++;
}
totalScore++

```

To get the percentage, you just need to use your variables that have been created like so:

```
percentage = userScore/totalScore*100
System.out.println("Your percentage: "+percentage.toString());

```
I think the easiest way to do this would be to keep track of the number of questions asked and the number of correct answers. Declare the following variables at the top of your code:

```
int questions = 0;
int correctAnswers = 0;

```

Each time you print out a question, increase the question count. For each correct answer, increase the correctAnswer count. Finally after all questions are answered:

```
int percent = (correctAnswers * 100)/questions

```

For example if they got 5 correct answers out of 10 then percent would contain the integer value 50. Then simply output it to the user:

```
System.out.println("Your percent correct is:" + percent);

```