我正在使用enum/switch case和Zeller的公式来表示一年中的哪一天,一个特定的日期将是哪一天。在我实现代码的枚举/开关部分的前几天,我的代码正在打印(如下所示)。在我放入enum/switch大小写之后,当我在DrJava中运行它时,它确实会提示日期、月份和年份,但是一旦它通过switch大小写,就不会打印任何内容
import java.util.*;
public class Zeller {
public enum DaysOftheWeek {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY;
}
private static int value;
public Zeller (int value){
this.value = value;
}
public int getValue(){
return this.value;
}
public static void main(String[] args) {
DetermineDay(value); // Create a Scanner
Scanner input = new Scanner(System.in);
// Prompt the user to enter a year, month and a day
System.out.print("Enter month: 1-12: ");
int month = input.nextInt();
System.out.print("Enter the day of the month: 1-31: ");
int day = input.nextInt();
System.out.print("Enter year (e.g., 2008): ");
int year = input.nextInt();
// Check if the month is January or February
// If the month is January and February, convert to 13, and 14,
// and year has to -1. (Go to previous year).
if (month == 1 || month == 2) {
month += 12;
year--;
}
// Compute the answer
int k = year % 100; // The year of the century
int j = (int)(year / 100.0); // the century
int q = day;
int m = month;
int h = (q + (int)((13 * (m + 1)) / 5.0) + k + (int)(k / 4.0)
+ (int)(j / 4.0) + (5 * j)) % 7;
value = h;
System.out.println(value);
}
public static String DetermineDay(int value){
String result = "Day of the week is ";
switch (value){
case 1 :
System.out.println(result + "Sunday");
break;
case 2 :
System.out.println(result + "Monday");
break;
case 3:
System.out.println(result + "Tuesday");
break;
case 4:
System.out.println(result + "Wednesday");
break;
case 5:
System.out.println(result + "Thursday");
break;
case 6:
System.out.println(result + "Friday");
break;
case 7 :
System.out.println( result + "Saturday");
break;
default :
System.out.println ("Looks like that day doesn't exist");
break;
}
return result;
}
}
>
在deterneDay结束时,您不需要返回结果,因为您已经在开关中sop了结果。
import java.util.*;
public class Zeller {
public enum DaysOftheWeek {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY;
}
private static int value;
public Zeller (int value){
this.value = value;
}
public int getValue(){
return this.value;
}
public static void main(String[] args) {
// Create a Scanner
Scanner input = new Scanner(System.in);
// Prompt the user to enter a year, month and a day
System.out.print("Enter month: 1-12: ");
int month = input.nextInt();
System.out.print("Enter the day of the month: 1-31: ");
int day = input.nextInt();
System.out.print("Enter year (e.g., 2008): ");
int year = input.nextInt();
// Check if the month is January or February
// If the month is January and February, convert to 13, and 14,
// and year has to -1. (Go to previous year).
if (month == 1 || month == 2) {
month += 12;
year--;
}
// Compute the answer
int k = year % 100; // The year of the century
int j = (int)(year / 100.0); // the century
int q = day;
int m = month;
int h = (q + (int)((13 * (m + 1)) / 5.0) + k + (int)(k / 4.0) + (int)(j / 4.0) + (5 * j)) % 7;
value = h;
System.out.println(value);
DetermineDay(value);
}
public static void DetermineDay(int value){
String result = "Day of the week is ";
switch (value){
case 1 :
System.out.println(result + "Sunday");
break;
case 2 :
System.out.println(result + "Monday");
break;
case 3:
System.out.println(result + "Tuesday");
break;
case 4:
System.out.println(result + "Wednesday");
break;
case 5:
System.out.println(result + "Thursday");
break;
case 6:
System.out.println(result + "Friday");
break;
case 7 :
System.out.println( result + "Saturday");
break;
default :
System.out.println ("Looks like that day doesn't exist");
break;
}
}
}
本文向大家介绍用CSS实现tab切换相关面试题,主要包含被问及用CSS实现tab切换时的应答技巧和注意事项,需要的朋友参考一下 1.用label结合单选按钮radio接受切换tab的单击 2.用zindex层级来显示当前tab页对应的内容 3.用css兄弟选择器选中对应的tab页签和内容页,添加相应的样式
我想添加一个切换按钮,允许PasswordField显示所写的内容,所以我创建了一个Textfield和一个PasswordField,它们共享GridPane中的位置,单击复选框将在两者之间切换。然而,问题是,当我按Tab从Username TextField导航到PasswordField时,它首先集中在不可见的TextField上,然后我必须再次按Tab。因此,总而言之,要从Username
我实现了一个自定义工具栏并将其作为操作栏。 但是,当当前片段被新片段替换时,汉堡图标不会变为后箭头。但当切换到新的活动时,返回箭头会正确出现。有人知道这里缺少什么吗? 感谢您的帮助。
本文向大家介绍php打印输出棋盘的实现方法,包括了php打印输出棋盘的实现方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了php打印输出棋盘的两种实现方法。分享给大家供大家参考。具体实现方法如下: 例子1,代码如下: 例子2 简单实现棋盘-for循环 实现这个棋盘首先我们想想棋盘是怎么样的,是有很多个方格组成,然后由黑色和白色的相间的方格组成,首先我们先把方格画出来,代码如下: 看到上
我正在尝试为我的响应式网站创建一个侧菜单。我对JavaScript不是很擅长,但它很管用!(目前为止) 我的问题是,我正在切换 类,使它从左侧出现和消失。要单击的按钮在 内容的外部,而要关闭的按钮是 内容内部的一个简单文本。 所以,我的HTML看起来是这样的: 这就是我想要切换的导航。要打开的按钮应为以下图像: CSS: 和我的JavaScript: 到目前为止还管用!但是,当我单击“关闭文本”时
我如何才能使打印在控制台中的消息不是直接发出,而是一点一点地发出