String must be 6 characters, first 3 must be letters, last 3 must be digits
Here is my code:
import java.util.Scanner; public class ValidTicket { public static void main (String[] args){ Scanner in = new Scanner (System.in); String id; int c=' ',i; int letterCount=0, digitCount=0; System.out.printf("Enter ticked id\n"); id= in.nextLine(); if (id.length() != 6) { System.out.printf("Invalid ticket id\n"); } else if (id.length() == 6) { //c= id.charAt(i); for (i=0; i<= id.length() -3; i++)//first 3 characters { c= id.charAt(i); if (Character.isUpperCase(c) || Character.isLowerCase(c)) { letterCount++; } } for(i=0; i> id.length() -3; i++)//last 3 characters { c= id.charAt(i); if (Character.isDigit(c)) { digitCount++; } { }// end if if (letterCount == 3 && digitCount==3) { System.out.printf("Valid ticket id\n"); } else System.out.printf("Invalid ticket id\n"); } }}}
However when I run my program, it does not work:
After I enter the string nothing happens.
Please help