Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I keep getting the following error:


Main.java:38: error: '.class' expected
main(String[] args);
^




//FULL CODE





Java
import java.util.Scanner;
import java.util.*;

public class Main {
    
    public static Scanner scan = new Scanner(System.in);
    
    public static void main(String[] args) {
        
        game Game = new game();
        
        String name, birthday, age;
        
        System.out.println("To get started, enter your name.");
        
        name = scan.nextLine();
        
        System.out.println("Enter your Date Of Birth. (YY, MM, DD)");
        
        birthday = scan.nextLine();
        
        //CALCULATING AGE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        
            Date now = new Date().getTime();
            
            age = now - birthday;
        
        
        
        // DONE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        
        System.out.println("Are you " + age);
        String ans = scan.nextLine();
        
        if (ans == "yes" || ans == "Yes") {
            Game.theGame();
        } else if (ans == "no" || ans == "No") {
            main(String[] args);
        }
    }
}


What I have tried:

I have tried deleting classes, replacing, even starting from scratch.
Posted
Updated 18-Apr-18 12:16pm
v2

Java
// this line is a method call, not a definition.
main(String[] args);
// it should be just
main(args);
 
Share this answer
 
Do you mean somehting like

Java
import java.util.Scanner;
import java.util.*;
import java.time.*;
import java.time.format.*;

public class Game
{
  public static void main(String[] args)
  {
    Scanner scan = new Scanner(System.in);
    String name, birthday;
    long age;
    String answer;

    do
    {
      System.out.println("To get started, enter your name.");

      name = scan.nextLine();

      System.out.println("Enter your Date Of Birth. (YYYY MM DD)");

      birthday = scan.nextLine();

      //CALCULATING AGE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu MM dd", Locale.ENGLISH);
      LocalDate dateofbirth = LocalDate.parse(birthday, formatter);
      LocalDate now = LocalDate.now();
      age = java.time.temporal.ChronoUnit.YEARS.between( dateofbirth , now );
      // DONE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

      System.out.println("Are you " + age);
      answer = scan.nextLine();
    } while ( ! answer.toUpperCase().equals("YES") );

    System.out.println("Goodbye " + name );
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900