I need help writing a program that reads to positive integers, one at a time, in 5 attempts.
I must leave one attempt to guess the second integer. So if the user does not input the correct answer by the fourth attempt, they can not get the first integer right.
This is the code I have so far.
package readtwopostiveinteger; import java.util.*; import java.io.*; public class ReadTwoPostiveInteger { private static final int numAttempts=5; private static int posInt; public static void main(String[] args) { int i = 0; System.out.println("Enter two postive integers,one at a time, # of Attemps Remaining:"+numAttempts); Scanner keyb = new Scanner(System.in); for(i=1; i<=numAttempts-1; i++) { try { posInt = keyb.nextInt();{ if (posInt>0) System.out.println("Correct");} if (posInt<=0) throw new InputMismatchException(); } catch(InputMismatchException ime){ System.out.println("Your Input was not a positive integer"); if (i== numAttempts) System.out.println ("sorry"); else System.out.println("Enter a postive integer,#of attemps remaining:" +numAttempts); continue;} } } }