我在获取构造函数中的变量以显示在我的 main 方法的输出中时遇到问题。我可以让程序只使用方法来工作,但是,使用构造函数时会出现问题。任何朝着正确方向的帮助或提示都会很棒!
public class Time {
public static void main (String[] args) {
TimeCalculations time1 = new TimeCalculations();
System.out.println(time1.getCurrentTime());
System.out.println(time1.getElaspedTime());
public static long input() {
Scanner input = new Scanner(System.in);
System.out.println("Enter a time");
return TimeCalculations.elaspedTime = input.nextLong();}
class TimeCalculations {
public long currentTime;
public static long elaspedTime;
public TimeCalculations() {
currentTime = System.currentTimeMillis();
this.currentTime = currentTime;
}
public TimeCalculations(long currentTime, long elaspedTime) {
elaspedTime = currentTime -Time.input();
}
public long getCurrentTime() {
return this.currentTime;
}
public long getElaspedTime() {
return TimeCalculations.elaspedTime;
}