辅导java、辅导PrintNumberInWord程序设计、java代作辅导、java辅导
讲解Database|解析Haskell程序
Exercise PrintNumberInWord (nested-if, switch-case): Write a program called PrintNumberInWord which prints "ONE", "TWO",... , "NINE", "OTHER" if the int variable "number" is 1, 2,... , 9, or other, respectively. Use (a) a "nested-if" statement; (b) a "switch-case" statement.
Hints:
/*
* Trying nested-if and switch-case statements.
*/
public class PrintNumberInWord { // Save as "PrintNumberInWord.java"
public static void main(String[] args) {
int number = 5; // Set the value of "number" here!
// Using nested-if
if (number == 1) {
System.out.println( ...... );
} else if ( ...... ) {
......
} else if ( ...... ) {
......
......
} else {
......
}
// Using switch-case
switch(number) {
case 1: System.out.println( ...... ); break; // Don't forget "break"
case 2: System.out.println( ...... ); break;
......
......
default: System.out.println( ...... );
}
}
}
Exercise PrintDayInWord (nested-if, switch-case): Write a program called PrintDayInWord which prints “Sunday”, “Monday”, ... “Saturday” if the int variable "day" is 0, 1, ..., 6, respectively. Otherwise, it shall print “Not a valid day”. Use (a) a "nested-if" statement; (b) a "switch-case" statement.