Menu List and interaction I am wondering if someone can review my code and tell me if there is a way to enhance it and make it more efficient.

import java.util.Scanner;

public class apples {
    public static void main (String[] args){
        Scanner input = new Scanner(System.in);

        int selection;

        for (int i=0; i&lt;4;i++){
            System.out.println("Please enter the selection you would like");
            System.out.println("Enter 1 for Coffee");
            System.out.println("Enter 2 for Tea");
            System.out.println("Enter 3 for Juice");
            System.out.println("Enter 4 for Fizzy Drink");
            selection = input.nextInt();
            if(selection==1){
                System.out.println("You have chosen coffee");
            }
            if(selection==2){
                System.out.println("You have chosen tea");
            }
            if(selection==3){
                System.out.println("You have chosen juice");
            }
            if(selection==4){
                System.out.println("You have chosen fizzy drink");
            }
            if(selection&lt;1 || selection&gt;4){
                System.out.println("You have made a wrong selection, please re-select");
            }
        }
    }
}
Whenever you find you have a situation where you are tring to match values to numbers, especically sequential numbers, the trick is to use an array. This makes the whole thing simpler, and centralizes the logic in one place, and the data in another.

Before we go there, though, some other things are:


Java class names should be Pascal case (upper-case word-starters), so it should be called Apple, and not apple.
There is no need to "pre-declare" variables. int selection; is unnecessary, just make the setting line: int selection = input.nextInt();


For example, your code could easily be:

import java.util.Scanner;

public class Apple {

    private static String[] DRINKS = { "Coffee", "Tea", "Juice", "Fizzy Drink" };

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        for (int i = 0; i &lt; 4; i++) {
            System.out.println("Please enter the selection you would like");

            for (int d = 0; d &lt; DRINKS.length; d++) {
                System.out.printf("Enter %d for %s\n", d + 1, DRINKS[d]);
            }
            int selection = input.nextInt() - 1;
            if (selection &gt;= 0 &amp;&amp; selection &lt; DRINKS.length) {
                System.out.println("You have chosen " + DRINKS[selection]);
            } else {
                System.out.println("You have made a wrong selection, please re-select");
            }
        }
    }
}


Note how I have reused the DRINKS array when both printing the prompt, and selecting the Drink. Also note that you can add drinks just by changing the array.

Finally, I find that using printf(...) is convenient when formatting data.