统计信息

  • 访问数:14546
  • 博客数:143
  • 建立时间:2008-01-05
  • 更新时间:2008-10-15
我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!

P2Q2

2008-01-21 16:47:03

天气: 晴朗 心情: 高兴

/*P2Q2
 * Name:Wang Chaoran
 * Description:(Checking whether a number is even)
Write a program that reads an integer and checks whether it is even.
For example, if your input is 25, the output should be:
Is 25 an even number? false
If your input is 2000, the output should be:
Is 2000 an even number? true
*/
import java.util.Scanner;
class P2Q2
{
  public static void main(String[] args)
  {
   //Step One:Create a scanner
    Scanner scan = new Scanner(System.in);
    //Step Two:Read in an integer
    System.out.println("Please input an integer");
    int integer = scan.nextInt();
    //Step Three:Compute and output the result
    if (integer %2 ==0)
    {
      System.out.println("Is "+integer+" an even number? true");
    }
    else
    {
      System.out.println("Is "+integer+" an even number? false");
    }
     
    }
  }

加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

Powered by X-Space 1.2 © 2001-2006 Comsenz Technology Ltd