أحتاج إلى مساعدة بشأن خطأ جافا. الفئة المتوقعة


أستمر في الحصول على الخطأ التالي:

Main.java:38: خطأ: “.class” متوقع
الرئيسي (سلسلة[] الحجج)؛
^

//الرمز الكامل

جافا
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);
        }
    }
}

ما حاولت:

لقد حاولت حذف الفصول واستبدالها وحتى البدء من الصفر.

الحل 1

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

الحل 2

هل تقصد شيئا مثل

جافا
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 );
  }
}

コメント

タイトルとURLをコピーしました