联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2018-06-16 05:07

Exercise CheckOddEven (if-else): Write a program called CheckOddEven which prints "Odd Number" if the int variable “number” is odd, or “Even Number” otherwise. The program shall always print “BYE!” before exiting.


Hints: n is an even number if (n % 2) is 0; otherwise, it is an odd number.


/*

* Trying if-else statement and modulus (%) operator.

*/

public class CheckOddEven {   // Save as "CheckOddEven.java"

  public static void main(String[] args) {  // Program entry point

     int number = 49;       // Set the value of "number" here!

     System.out.println("The number is " + number);

     if ( ...... ) {

        System.out.println( ...... );

     } else {

        System.out.println( ...... );

     }

     System.out.println( ...... );

  }

}

Exercise CheckPassFail (if-else): Write a program called CheckPassFail which prints "PASS" if the int variable "mark" is more than or equal to 50; or prints "FAIL" otherwise. The program shall always print “DONE” before exiting.


Hints:


/*

* Trying if-else statement.

*/

public class CheckPassFail {  // Save as "CheckPassFail.java"

  public static void main(String[] args) {  // Program entry point

     int mark = 49;  // Set the value of "mark" here!

     System.out.println("The mark is " + mark);

     if ( ...... ) {

        System.out.println( ...... );

     } else {

        System.out.println( ...... );

     }

     System.out.println( ...... );

  }

}

Take note of the source-code indentation!!! Whenever you open a block with '{', indent all the statements inside the block by 3 or 4 spaces. When the block ends, un-indent the closing '}' to align with the opening statement.


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp