Java第三章習題3-3(彩票中獎2)
阿新 • • 發佈:2019-02-13
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); } }