-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLottery.java
More file actions
45 lines (45 loc) · 1.44 KB
/
Lottery.java
File metadata and controls
45 lines (45 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.example;
import java.util.Scanner;
public class Lottery {
public static void main(String args[]){
System.out.println("|| WELCOME TO LOTTERY GAME ||\nGET WIN WIN WIN !!! ");
System.out.println("FOUR DIGIT MATCH WIN ₹100000 ");
System.out.println("THREE DIGIT MATCH WIN ₹10000 ");
System.out.println("TWO DIGIT MATCH WIN ₹2000 ");
System.out.println("ONE DIGIT MATCH WIN ₹100 ");
System.out.println("ANYONE DIGIT NOT SAME NO REWARD ");
//To generate Random number in range to [0.10000)
int randomNumber = (int)Math.random()*10000 + 1 ;
//To promote user entering four digits number
System.out.print("Enter a lottery numbers \n( e.g. 5 => 0005 ) : ");
Scanner input = new Scanner(System.in);
int lotteryNumber = input.nextInt();
int count = 0;
while(lotteryNumber>0){
if(lotteryNumber % 10 == randomNumber % 10)
count++;
lotteryNumber/=10;
randomNumber/=10;
}
if(count>4)
System.out.println("Please Read the Instruction and than chose your ticket");
else {
switch(count){
case 1 :
System.out.println("YOU WIN ₹100");
break ;
case 2 :
System.out.println("YOU WIN ₹2000");
break;
case 3 :
System.out.println("YOU WIN ₹10000");
break;
case 4 :
System.out.println("YOU WIN ₹100000");
break ;
default :
System.out.println("SORRY , YOU AREN'T WIN REWARD \nBETTER LUCK NEXT TIME");
}
}
}
}