我需要帮助java错误.class预期 [英] I need help with java error .class expected
本文介绍了我需要帮助java错误.class预期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直收到以下错误:
Main.java:38:错误:'。class'预期
main(String [] args);
^
//完整的代码
I keep getting the following error:
Main.java:38: error: '.class' expected
main(String[] args);
^
//FULL CODE
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.
推荐答案
// this line is a method call, not a definition.
main(String[] args);
// it should be just
main(args);
你的意思是某些像
Do you mean somehting like
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 );
}
}
这篇关于我需要帮助java错误.class预期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文