我需要创建一些能够在GMT中找到当前小时并将其转换为EST的东西.
当我尝试编译并运行程序时,我收到此错误:currentHourEST cannot be resolved to a variable.我认为我的问题if else在于我将变量分配错误或其他内容的陈述中的某个地方.
// Obtain total milliseconds since midnight, Jan 1, 1970
long totalMilliseconds = System.currentTimeMillis();
// Seconds
long totalSeconds = totalMilliseconds / 1000;
long currentSecond = totalSeconds % 60;
// Minutes
long totalMinutes = totalSeconds / 60;
long currentMinute = totalMinutes % 60;
// Hours
long totalHours = totalMinutes / 60;
long currentHour = totalHours % 24;
// Read in EST offset
long offSetAdded = currentHour - 5;
// …Run Code Online (Sandbox Code Playgroud) 如果我使用for循环来查找运行时n之间的数字总和.但是如果我创建一个递归函数,例如:0 and nO(n)
int sum(int n) {
if(n == 0)
return 0;
return n + sum((n - 1));
}
Run Code Online (Sandbox Code Playgroud)
我的运行时间还会O(n)吗?