Grade calculator for a project with four aspects I have a program that will ask the user to input their grades for 4 different sections of a project, then tell them what their total mark is, what grade they got and how many marks away they were from the next grade. I managed to make a single loop for all inputs rather than having a loop for each individual one, but there are still quite a lot of if statements to determine what grade they got and how far away they were from the next one, and I can't figure out how to optimise it since I'm still very new to Java.

import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Scanner;

public class PortfolioGrade {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String[] words = new String[]{"Analysis", "Design", "Implementation", "Evaluation"};
        int[] marks = new int[words.length];
        for(int counter = 1; counter &lt;= words.length; counter++) {
            System.out.println("Enter your mark for the '" + words[counter - 1] + "' part of the project: ");
            while(true) {
                try {
                    Scanner reader = new Scanner(System.in);
                    marks[counter - 1] = reader.nextInt();
                    if(marks[counter - 1] &lt; 0 || marks[counter - 1] &gt; 25) {
                        System.out.println("Please input a number between 0 and 25.");
                        continue;
                    }
                    break;
                } catch(InputMismatchException e) {
                    System.out.println("Please input a valid integer.");
                }
            }
        }

        int totalmark = Arrays.stream(marks).sum();
        String grade = null;
        String nextgrade = null;
        Integer marksaway = null;

        if(totalmark &lt; 2) {
            grade = "U";
            marksaway = 2 - totalmark;
            nextgrade = "1";
        } else if(totalmark &gt;= 2 &amp;&amp; totalmark &lt; 4) {
            grade = "1";
            marksaway = 4 - totalmark;
            nextgrade = "2";
        } else if(totalmark &gt;= 4 &amp;&amp; totalmark &lt; 13) {
            grade = "2";
            marksaway = 13 - totalmark;
            nextgrade = "3";
        } else if(totalmark &gt;= 13 &amp;&amp; totalmark &lt; 22) {
            grade = "3";
            marksaway = 22 - totalmark;
            nextgrade = "4";
        } else if(totalmark &gt;= 22 &amp;&amp; totalmark &lt; 31) {
            grade = "4";
            marksaway = 31 - totalmark;
            nextgrade = "5";
        } else if(totalmark &gt;= 31 &amp;&amp; totalmark &lt; 41) {
            grade = "5";
            marksaway = 41 - totalmark;
            nextgrade = "6";
        } else if(totalmark &gt;= 41 &amp;&amp; totalmark &lt; 54) {
            grade = "6";
            marksaway = 54 - totalmark;
            nextgrade = "7";
        } else if(totalmark &gt;= 54 &amp;&amp; totalmark &lt; 67) {
            grade = "7";
            marksaway = 67 - totalmark;
            nextgrade = "8";
        } else if(totalmark &gt;= 67 &amp;&amp; totalmark &lt; 80) {
            grade = "8";
            marksaway = 80 - totalmark;
            nextgrade = "9";
        } else if(totalmark &gt;= 80) {
            grade = "9";
        }

        System.out.println("Your total mark was " + totalmark + ".");
        System.out.println("You got a Grade " + grade + ".");
        if(grade == "9") {
            System.out.println("You achieved the highest grade!");
        } else if(marksaway == 1) {
            System.out.println("You were " + marksaway + " mark away from a Grade " + nextgrade + ".");
        } else {    
            System.out.println("You were " + marksaway + " marks away from a Grade " + nextgrade + ".");
        }
    }
}
Because there are no holes you can simply have an array of "breakpoints".

int [] steps = new int[] { 2, 4, 13, 22, 31, 41, 54, 67, 80 };
int i;

for(i=0; i&lt;steps.length &amp;&amp; totalmark&gt;=steps[i]; i++);
grade = i==0 ? "U" : ""+i;
if(i&lt;steps.length) marksaway=steps[i]-totalmark; 
nextgrade=""+(i+1);