Pretty straightforward. Don’t even need to use this Card class that I have been using for the past few questions!
import java.io.PrintWriter; import java.util.Scanner; /** * * @author Sanchit M. Bhatnagar * @see http://uhunt.felix-halim.net/id/74004 * */ public class P10646 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int N = sc.nextInt(); for (int zz = 1; zz <= N; zz++) { String[] deck = new String[52]; for (int i = 0; i < 52; i++) { deck[i] = sc.next(); } int Y = 0; int last = -1; int count = 0; for (int i = 25; i >= 0 && count < 3; i--) { int val = getVal(deck[i]); Y += val; i -= (10 - val); count++; last = i; } if (Y <= last) { out.println("Case " + zz + ": " + deck[Y - 1]); } else { out.println("Case " + zz + ": " + deck[26 + (Y - last) - 1]); } } sc.close(); out.close(); } private static int getVal(String card) { char c = card.charAt(0); if (c >= '2' && c <= '9') { return Integer.parseInt(c + ""); } return 10; } }