Java第三章习题3-3(彩票中奖2)

来源:互联网 发布:原生js获取json文件 编辑:程序博客网 时间:2024/04/30 08:41


LotteryNumber.java

/* * To change this template, choose Tools | Templates * and open the template in the editor. *//** * * @author Administrator */public class LotteryNumber {    public void giveMess(int number){        if(number/10000>=10 || number/10000<1){            System.out.println("please input a five digit number:");                    }        else{            int num1=number%10;            int num2=number%100;            int num3=number%1000;            int count = 0 ;  //用来记录前面是否得奖,避免重复            if(num3==875||num3==326||num3==596){                System.out.println("Congratulations you won the first place .");                count=count+1;            }            else if(num2==29 || num2==46 ||num2==21){                System.out.println("Congratulations you won the second place .");                count=count+1;            }            else if(num1==1 || num1==3 ||num1==9){                System.out.println("Congratulations you won the third place .");            }            else {                System.out.println("It's a pity that you didn't win the prize. ");            }                        }                            }    }

Test.java

import java.util.Scanner;/* * To change this template, choose Tools | Templates * and open the template in the editor. *//** * * @author Administrator */public class Test {    public static void main(String[] args){        Scanner reader=new Scanner(System.in);        System.out.println("please input your number:");        int number=reader.nextInt();        LotteryNumber lo=new LotteryNumber();        lo.giveMess(number);    }    }


0 0
原创粉丝点击