作业

*3-1
* 功能:产生随机数来执行减法,并从用户中获得数字用以判断正误。
*/
import java.util.Scanner;

public class AdditionQuiz {
  public static void main(String[] args)
  {
    int number1=(int)(System.currentTimeMillis()%10);
    int number2=(int)(System.currentTimeMillis()/7%10);

    Scanner input=new Scanner(System.in);

    System.out.print(number1+"+"+number2+"=?");

    int answer=input.nextInt();

    System.out.println(number1+"+"+number2+"="+answer+"你的答案是:"+(number1+number2==answer));


  }
}

 

 

/*3-2
* 功能:输入一个整数,如果是5的倍数,就打印HiFive,如果是2的倍数,就打印HiEven。
*/

import java.util.Scanner;

public class SimpleIfDemo
{
    public static void main(String[] args)
    {
      Scanner input =new Scanner(System.in);
      System.out.println("输入一个整数:");
      int number =input.nextInt();

      if(number%5==0)
      System.out.println("HiFive");
      else if(number%2==0)
      System.out.println("HiEven");
    }

}

 

 

/*3-3
*功能:就是实现一个减法,然后判断正确还是错误。
*/
import java.util.Scanner;

public class SubtractionQuiz {
    public static void main(String[] args)
    {
      int number1=(int)(Math.random()*10);
      int number2=(int)(Math.random()*10);

      if (number1<number2)
      {
        int temp=number1;
        number1=number2;
        number2=temp;
      }
      System.out.print(number1+"-"+number2+"=?");

      Scanner input =new Scanner(System.in);
      int answer=input.nextInt();
      if ((number1-number2)==answer)
        System.out.println("你的答案是正确的!加油加油哦!"3);
      else 
        System.out.println("你的答案是错误的,下次努力哈。");
    }
}

 

 

import java.util.Scanner;
public class ComputeTax {
    public static void main(String[] args)
    {
      Scanner input =new Scanner(System.in);
      System.out.println("一大堆东西。");
      int status=input.nextInt();
      System.out.println("请输入你的收入(如实汇报):");
      double income=input.nextDouble();
      double tax=0;
      if (status==0)
      {
      if(income<=8350)
        tax=income*0.10;
      else if(income<=33950)
        tax=8350*0.1+(income-8350)*0.15;
      else if(income<=82250)
      tax=8350*0.1+(33950-8350)*0.15+(income-33950)*0.25;
        else if(income<=171550)
        tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(income-82250)*0.28;
      else if(income<=372590)
        tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82250)*0.28+(income-171550)*0.33;
      else
        tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82250)*0.28+(372590-171550)*0.33+(income-372590)*0.35;

    }
    else if(status==1)
    {}
    else if(status==2)
    {}
    else if(status==3)
    {}
    else
    {
      System.out.println("错误:你钱这么多?不存在的");
      System.exit(1);
    }
     System.out.println("Tax is"+(int)(tax*100)/100.0);
    }


}

 

 

import java.util.Scanner;
public class TestBooleanOperators {
  public static void main(String[] args)
  {
    Scanner input =new Scanner(System.in);
    System.out.println("请输入一个整数:");
    int number =input.nextInt();
    if(number%2==0&&number%3==0)
    System.out.println("数字可以被2、3整除。");
    if(number%2==0||number%3==0)
    System.out.println("数字可以被2或3整除。");
    if(number%2==0^number%3==0)
    System.out.println("数字不可以被2、3整除。");

  }
}

 

 

import java.util.Scanner;
public class LeapYear {
  public static void main(String[] args)
  {
    Scanner input =new Scanner(System.in);
    System.out.print("请输入年份:");
    int year=input.nextInt();
    boolean isLeapYear=(year%4==0&&year%100!=0)||(year%400==0);
    System.out.println(year+"是闰年"+isLeapYear);

  }
}

 

 

 

posted @ 2017-10-16 13:05  黄浩然  阅读(163)  评论(0编辑  收藏  举报