date andjava switchh原声带

请高手帮我翻译一下这段说明!朋友从国外带回一块手表,关于闹钟设计的说明有点看不懂,请帮忙翻译一下,谢谢啦!Pulling out the alarm switch activates alarm and pushing it deactivates it. To set the time and date _作业帮
拍照搜题,秒出答案
请高手帮我翻译一下这段说明!朋友从国外带回一块手表,关于闹钟设计的说明有点看不懂,请帮忙翻译一下,谢谢啦!Pulling out the alarm switch activates alarm and pushing it deactivates it. To set the time and date
请高手帮我翻译一下这段说明!朋友从国外带回一块手表,关于闹钟设计的说明有点看不懂,请帮忙翻译一下,谢谢啦!Pulling out the alarm switch activates alarm and pushing it deactivates it. To set the time and date on watches equipped with alarms, the alarm button must be off to switch between alarm and time. Both normal time and alarm time are displayed using the same hour and minute.Pull
the alarm switch out to postion.Pull
the crown out to postion. The hands will quickly go round clockwise. When the hands stop, it's now showing alarm time(confirmation sound).Push
the crown back to the postion, and the hands will quickly return to normal time and there will be a(confirmation sound).When the alarm set at say 4:00, the alarm will sound for 20 seconds at 4:00 in the afternoon and 4:00 in the morning. So turn it off after it sounds at 4:00 PM, unless you want to wake up at 4:00 AM, too.
拉出警报开关刺激警报,而且推动它解除动员它.为了要支使时间和日期对付被装备警报的手表,警报钮扣一定去在警报和时间之间转变.常态时间和警报时间使用同一个小时和分钟被显示.对 postion 在外拉警报开关.对 postion 在外拉王冠.手将会很快地顺时针方向绕道.当手停止的时候,它是现在成绩警报时间.(证实声音) 把王冠推动回到 postion,而且手将会很快地回到正常的时间而且将会有一 (证实声音).当警报组在发言权 4:00 ,警报将会午后在 4:00 听 20 秒和在早晨 4:00.因此把它关掉在它在下午 4:00 听之后,除非你想要也在早上 4:00 醒来.postion,这个单词打错了吗?没这个Documentation
The Java& Tutorials
The switch Statement
Unlike if-then and if-then-else statements, the switch statement can have a number of possible execution paths. A switch works with the byte, short, char, and int primitive data types. It also works with enumerated types (discussed in
class, and a few special classes that wrap certain primitive types:
(discussed in
The following code example,
, declares an int named month whose value represents a month. The code displays the name of the month, based on the value of month, using the switch statement.
public class SwitchDemo {
public static void main(String[] args) {
int month = 8;
String monthS
switch (month) {
monthString = &January&;
monthString = &February&;
monthString = &March&;
monthString = &April&;
monthString = &May&;
monthString = &June&;
monthString = &July&;
monthString = &August&;
monthString = &September&;
case 10: monthString = &October&;
case 11: monthString = &November&;
case 12: monthString = &December&;
default: monthString = &Invalid month&;
System.out.println(monthString);
In this case, August is printed to standard output.
The body of a switch statement is known as a switch block. A statement in the switch block can be labeled with one or more case or default labels. The switch statement evaluates its expression, then executes all statements that follow the matching case label.
You could also display the name of the month with if-then-else statements:
int month = 8;
if (month == 1) {
System.out.println("January");
} else if (month == 2) {
System.out.println("February");
// and so on
Deciding whether to use if-then-else statements or a switch statement is based on readability and the expression that the statement is testing. An if-then-else statement can test expressions based on ranges of values or conditions, whereas a switch statement tests expressions based only on a single integer, enumerated value, or String object.
Another point of interest is the break statement. Each break statement terminates the enclosing switch statement. Control flow continues with the first statement following the switch block. The break statements are necessary because without them, statements in switch blocks fall through: All statements after the matching case label are executed in sequence, regardless of the expression of subsequent case labels, until a break statement is encountered. The program
shows statements in a switch block that fall through. The program displays the month corresponding to the integer month and the months that follow in the year:
public class SwitchDemoFallThrough {
public static void main(String[] args) {
java.util.ArrayList&String& futureMonths =
new java.util.ArrayList&String&();
int month = 8;
switch (month) {
futureMonths.add(&January&);
futureMonths.add(&February&);
futureMonths.add(&March&);
futureMonths.add(&April&);
futureMonths.add(&May&);
futureMonths.add(&June&);
futureMonths.add(&July&);
futureMonths.add(&August&);
futureMonths.add(&September&);
case 10: futureMonths.add(&October&);
case 11: futureMonths.add(&November&);
case 12: futureMonths.add(&December&);
if (futureMonths.isEmpty()) {
System.out.println(&Invalid month number&);
for (String monthName : futureMonths) {
System.out.println(monthName);
This is the output from the code:
Technically, the final break is not required because flow falls out of the switch statement. Using a break is recommended so that modifying the code is easier and less error prone. The default section handles all values that are not explicitly handled by one of the case sections.
The following code example,
, shows how a statement can have multiple case labels. The code example calculates the number of days in a particular month:
class SwitchDemo2 {
public static void main(String[] args) {
int month = 2;
int year = 2000;
int numDays = 0;
switch (month) {
case 1: case 3: case 5:
case 7: case 8: case 10:
numDays = 31;
case 4: case 6:
case 9: case 11:
numDays = 30;
if (((year % 4 == 0) &&
!(year % 100 == 0))
|| (year % 400 == 0))
numDays = 29;
numDays = 28;
System.out.println(&Invalid month.&);
System.out.println(&Number of Days = &
+ numDays);
This is the output from the code:
Number of Days = 29
Using Strings in switch Statements
In Java SE 7 and later, you can use a String object in the switch statement's expression. The following code example,
, displays the number of the month based on the value of the String named month:
public class StringSwitchDemo {
public static int getMonthNumber(String month) {
int monthNumber = 0;
if (month == null) {
return monthN
switch (month.toLowerCase()) {
case &january&:
monthNumber = 1;
case &february&:
monthNumber = 2;
case &march&:
monthNumber = 3;
case &april&:
monthNumber = 4;
case &may&:
monthNumber = 5;
case &june&:
monthNumber = 6;
case &july&:
monthNumber = 7;
case &august&:
monthNumber = 8;
case &september&:
monthNumber = 9;
case &october&:
monthNumber = 10;
case &november&:
monthNumber = 11;
case &december&:
monthNumber = 12;
monthNumber = 0;
return monthN
public static void main(String[] args) {
String month = &August&;
int returnedMonthNumber =
StringSwitchDemo.getMonthNumber(month);
if (returnedMonthNumber == 0) {
System.out.println(&Invalid month&);
System.out.println(returnedMonthNumber);
The output from this code is 8.
The String in the switch expression is compared with the expressions associated with each case label as if the
method were being used. In order for the StringSwitchDemo example to accept any month regardless of case, month is converted to lowercase (with the
method), and all the strings associated with the case labels are in lowercase.
Note: This example checks if the expression in the switch statement is null. Ensure that the expression in any switch statement is not null to prevent a NullPointerException from being thrown.}

我要回帖

更多关于 java switch 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信