Printing a number based on a user-provided number Is there a better way to ask for input and give answers, but without so many lines? Each input will give a specific output according to a key that I use, but this many lines seems excessive. I'm a beginner to java and could use some ideas on how to optimize this coding.

    import java.util.Scanner; 
    class Test {
    public static void main (String [] args) {

    System.out.print ("Enter the day of the month - Answer: "); 
    Scanner inputFigure = new Scanner (System.in); 
    int i = inputFigure.nextInt (); 
    if ( i==1) { 
        System.out.println ("12");
    }
    else if (i==2) {
        System.out.println ("13");
    }
    else if (i==3) {
        System.out.println ("14");
    }
    else if (i==4) {
        System.out.println ("11");
    }
    else if (i==5) {
        System.out.println ("12");
    }
    else if (i==6) {
        System.out.println ("13");
    }
    else if (i==7) {
        System.out.println ("14");
    }
    else if (i==8) {
        System.out.println ("11");
    }
    else if (i==9) {
        System.out.println ("12");
    }
    else if (i==10) {
        System.out.println ("21");
    }
    else if (i==11) {
        System.out.println ("22");
    }
    else if (i==12) {
        System.out.println ("23");
    }
    else if (i==13) {
        System.out.println ("24");
    }
    else if (i==14) {
        System.out.println ("21");
    }   
    else if (i==15) {
        System.out.println ("22");
    }
    else if (i==16) {
        System.out.println ("23");
    }
    else if (i==17) {
        System.out.println ("24");
    }
    else if (i==18) {
        System.out.println ("21");
    }
    else if (i==19) {
        System.out.println ("22");
    }
    else if (i==20) {
        System.out.println ("31");
    }
    else if (i==21) {
        System.out.println ("32");
    }
    else if (i==22) {
        System.out.println ("33");
    }
    else if (i==23) {
        System.out.println ("34");
    }
    else if (i==24) {
        System.out.println ("31");
    }
    else if (i==25) {
        System.out.println ("32");
    }
    else if (i==26) {
        System.out.println ("33");
    }
    else if (i==27) {
        System.out.println ("34");
    }   
    else if (i==28) {
        System.out.println ("31");
    }
    else if (i==29) {
        System.out.println ("32");
    }
    else if (i==30) {
        System.out.println ("41");
    }
    else if (i==31) {
        System.out.println ("42");
    }
    else {
        System.out.println ("Invalid entry for the day. Try again.");
    }
}
}
The best way to shorten the code would be to write a formula for it.  That formula should be packaged into a function:

public static String outputForDay(int day) {
    if (!(1 &lt;= day &amp;&amp; day &lt;= 31)) {
        throw new IllegalArgumentException("Invalid entry for the day.");
    }
    int onesDigit = day % 10,
        tensDigit = day / 10;
    return Integer.toString(10 * (tensDigit + 1) + (onesDigit % 4) + 1);
}


Then, you would call the function like this:

public static void main(String[] args) {
    try (Scanner scanner = new Scanner(System.in)) {
        System.out.print("Enter the day of the month: ");
        System.out.println(outputForDay(scanner.nextInt()));
    } catch (IllegalArgumentException e) {
        System.out.println(e.getMessage());
    }
}