Java获取/设置日期程序赢得';不编译
程序将从用户处获取日、月和年,然后使用单独的类和单独的方法显示它们,以执行每个获取/设置部分以及显示功能 它没有编译,我得到一个错误: java:3:错误:需要类、接口或枚举 扫描器Obj=新扫描器(System.in); ^ 1错误Java获取/设置日期程序赢得';不编译,java,Java,程序将从用户处获取日、月和年,然后使用单独的类和单独的方法显示它们,以执行每个获取/设置部分以及显示功能 它没有编译,我得到一个错误: java:3:错误:需要类、接口或枚举 扫描器Obj=新扫描器(System.in); ^ 1错误 你的陈述不在课堂上。这不是声明变量的合适位置 将其作为成员移动到类中,或作为局部变量移动到方法中 import java.util.Scanner; public class Date{ int month; //instance variables i
你的陈述不在课堂上。这不是声明变量的合适位置 将其作为成员移动到类中,或作为局部变量移动到方法中
import java.util.Scanner;
public class Date{
int month; //instance variables
int day;
int year;
int m;
int d;
int y;
// consider calling it "obj" so it starts with a lowercase as per Java conventions
Scanner Obj = new Scanner(Systsem.in);
// other methods below snipped for brevity
}
变量声明应该在类或方法内部
import java.util.Scanner;
public class Date{
int month; //instance variables
int day;
int year;
int m;
int d;
int y;
// consider calling it "obj" so it starts with a lowercase as per Java conventions
Scanner Obj = new Scanner(Systsem.in);
// other methods below snipped for brevity
}