"Choose a number between 0-9" game This is a simple "Choose a number between 0-9" Game. It works perfectly but I'd like to know if there's a way to make my code smaller with the exact same functionality.

package firstGame;

    import java.util.Scanner;

    public class Player {

        static Scanner p2Name = new Scanner(System.in);
        static Scanner p1Name = new Scanner(System.in);
        static Scanner p3Name = new Scanner(System.in);

        static Scanner p1Num = new Scanner(System.in);
        static Scanner p2Num = new Scanner(System.in);
        static Scanner p3Num = new Scanner(System.in);

        String name;
        int age;
        int size;

        public static void main(String[] args) {




            // Create a random number generator (0-9)
            int number = (int) (Math.random() * 10);

            // Get Player1's name
            System.out.print("Player 1, please enter your name : ");
            String p1 = p1Name.nextLine();
            System.out.println("Welcome " + p1 + "!");

            // Get Player1's chosen number
            System.out.println("Please enter a number between 0 and 9");
            int p1Choice = p1Num.nextInt();
            System.out.println("");

            // Get Player2's name
            System.out.print("Player 2, please enter your name : ");
            String p2 = p2Name.nextLine();
            System.out.println("Welcome " + p2 + "!");

            // Get Player2's chosen number
            System.out.println("Please enter a number between 0 and 9");
            int p2Choice = p2Num.nextInt();
            System.out.println("");

            // Get Player3's name
            System.out.print("Player 3, please enter your name : ");
            String p3 = p3Name.nextLine();
            System.out.println("Welcome " + p3 + "!");

            // Get Player3's chosen number
            System.out.println("Please enter a number between 0 and 9");
            int p3Choice = p3Num.nextInt();
            System.out.println("");

            //Output generated number
            System.out.println("The number I was thinking of was : " + number);

            //if 1 player wins, output this
            if (number == p1Choice || number == p2Choice || number == p3Choice) {
                System.out.println("We have a winner!");
            }

            //Player1 won or lost?
            if (number == p1Choice) {
                System.out.println(p1 + " won!");
            } else {
                System.out.println(p1 + ", you lose!");
            }

            //Player2 won or lost?
            if (number == p2Choice) {
                System.out.println(p2 + " won!");
            } else {
                System.out.println(p2 + ", you lose!");
            }

            //Player3 won or lost?
            if (number == p3Choice) {
                System.out.println(p3 + " won!");
            } else {
                System.out.println(p3 + ", you lose!");
            }

        }

    }
static Scanner p2Name = new Scanner(System.in);
        static Scanner p1Name = new Scanner(System.in);
        static Scanner p3Name = new Scanner(System.in);

        static Scanner p1Num = new Scanner(System.in);
        static Scanner p2Num = new Scanner(System.in);
        static Scanner p3Num = new Scanner(System.in);



You don't need all those scanners.  One is plenty.  

        static Scanner scanner = new Scanner(System.in);


Then replace each call using one of the other variables with scanner.  

It's possible that you may have to call scanner.nextLine() after calling scanner.nextInt().  I haven't tried it.  

@BKSpurgeon in Java

Here's the @BKSpurgeon solution converted to Java:  

Program.java

class Program {

    public static void main(String[] args) {
        GameMaster g = new GameMaster(3);
        g.printResults();
    }

}


Player.java

class Player {

    static Scanner scanner = new Scanner(System.in);

    private String name;       
    private int number;

    public Player(int playerPosition) {
        name = inputName(playerPosition);
        printName();
        number = inputNumber();
        //scanner.nextLine(); // uncomment if needed
    }

    private void printName() {
        System.out.println("Welcome "+ name + "!");
    }

    private int inputNumber() {
        System.out.println("Please enter a number between 0 and 9");

        return scanner.nextInt();
    }

    private String inputName(int playerPosition) {
        System.out.println("Player " + playerPosition + ", please enter your name");

        return scanner.nextLine();
    }

    public String calculateResult(int winningNumber) {
        return name + ((winningNumber == number) ? " won!" : ", you lose!");
    }

}


GameMaster.java

public class GameMaster {

    private final int winningNumber;
    private final List&lt;Player&gt; players = new ArrayList&lt;&gt;();

    public GameMaster(int playerCount) {
        winningNumber = chooseWinningNumber();

        for (int i = 1; i &lt;= playerCount; i++) {
            players.add(new Player(i));
        }
    }

    public void printResults() {
        for (Player p : players) {
            System.out.println(p.calculateResult(winningNumber));
        }
    }

    private static int chooseWinningNumber() {
        return (int) (Math.random() * 10);
    }

}


I made a few tweaks to comply with Java coding conventions, but the structure is mostly the same.  

I haven't tried to run it, so beware of typos, etc.