统计信息

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

P2Q3

2008-01-21 17:10:00

天气: 晴朗 心情: 高兴

/*P2Q3
 *Name:Wang Chaoran
 *Description:(Using the &&, || and ^ operators)
Write a program that prompts the user to enter an integer
and determines whether it is divisible by 5 and 6, whether
it is divisible by 5 or 6, and whether it is divisible by 5 or 6,
but not both. For example, if your input is 10, the output should be
Is 10 divisible by 5 and 6? false
Is 10 divisible by 5 or 6? true
Is 10 divisible by 5 or 6, but not both? true
*/
import java.util.Scanner;
class P2Q3
{
  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();
  //Compute and display result
  if((integer % 5 == 0)&&(integer % 6 ==0))
  {
  System.out.println("Is "+integer+" divisible by 5 and 6? true");
  System.out.println("Is "+integer+" divisible by 5 or 6, but not both? false");
   System.out.println("Is "+integer+" divisible by 5 or 6? true");
  }
  else if((integer % 5 == 0)^(integer % 6 ==0))
  {
  System.out.println("Is "+integer+" divisible by 5 and 6? false");
  System.out.println("Is "+integer+" divisible by 5 or 6, but not both? true");
   System.out.println("Is "+integer+" divisible by 5 or 6? true");
  }
  else
  {
  System.out.println("Is "+integer+" divisible by 5 and 6? false");
  System.out.println("Is "+integer+" divisible by 5 or 6, but not both? false");
   System.out.println("Is "+integer+" divisible by 5 or 6? false");
  }
 
  }
}

加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

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