I need help figuring out to intakes a complete date and then validate that it is a real date.
This is what I have so far.
import java.util.Scanner;
public class numerology
{
public static void main( String args[])
{
Scanner input = new Scanner(System.in);
int month = 0;
int date = 0;
int year = 0;
char slash = '/';
int checker = 0; //a flag used to tell if the birthday enter is a validate one 0 = no 1 = yes
System.out.println ("Enter birthday(mm/dd/yyyy): ");
month = input.nextInt();
slash = input.next().charAt(0);
date = input.nextInt();
slash = input.next().charAt(0);
year = input.nextInt();
while (checker == 0)
{
if ( month < 1 || month > 12)
{
System.out.printf("Bad month: %d\n", month);
System.out.print("Re-enter birthday(mm/dd/yyyy): \n");
month = input.nextInt();
slash = input.next().charAt(0);
date = input.nextInt();
slash = input.next().charAt(0);
year = input.nextInt();
}
else
if ( slash != '/')
{
System.out.print ("Use forward slash");
System.out.print ("Re-enter birthday(mm/dd/yyyy): ");
month = input.nextInt();
slash = input.next().charAt(0);
date = input.nextInt();
slash = input.next().charAt(0);
year = input.nextInt();
I got more code that checks the date and year but I’m aready running into problems with the code I have now.
My problem at the moment is that the check ‘/’ won’t work.
Also when I run this loop, there is no way to exit it (it’s an infinite loop). It’s obviously a problem that I still am not able to solve for over a week of working on this. I have been trying to find a way to use the Int “checker” to somehow turn to a 1 so the loop will exit. However no luck on figuring that out either. So bascially should I scrap this entire thing and start over? If so, can someone point me in the right directions?
You should set
checker = 1somewhere inside your loop so that the condition in the while loop becomes false and the code will exit