首页 > > 详细

辅导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.
联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!