Member 13786429 Ответов: 2

Мне нужна помощь с java error .class expected


Я постоянно получаю следующую ошибку:


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




//ПОЛНЫЙ КОД





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);
        }
    }
}


Что я уже пробовал:

Я пробовал удалять классы, заменять, даже начинать с нуля.

2 Ответов

Рейтинг:
2

Richard MacCutchan

// this line is a method call, not a definition.
main(String[] args);
// it should be just
main(args);


Рейтинг:
1

CPallini

Вы имеете в виду что-то вроде

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 );
  }
}