-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomNumberGeneratorIn3Classes.java
More file actions
64 lines (63 loc) · 1.69 KB
/
RandomNumberGeneratorIn3Classes.java
File metadata and controls
64 lines (63 loc) · 1.69 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.*;
public class RandomNumberFor3Body
{
static int random1()
{
int x,i;
int[] a= new int[20];
for(i=0;i<20;i++)
{
a[i]= i+1;
}
x = (int)Math.floor(Math.random()*(a[19]-a[0]+1)+a[0]);
System.out.println("the random number is : "+x);
return 0;
}
static int random2()
{
int x,i;
int[] a= new int[20];
for(i=0;i<20;i++)
{
a[i]= i+21;
}
x = (int)Math.floor(Math.random()*(a[19]-a[0]+1)+a[0]);
System.out.println("the random number is : "+x);
return 0;
}
static int random3()
{
int x,i;
int[] a= new int[20];
for(i=0;i<20;i++)
{
a[i]= i+41;
}
x = (int)Math.floor(Math.random()*(a[19]-a[0]+1)+a[0]);
System.out.println("the random number is : "+x);
return 0;
}
public static void main(String[] args)
{
System.out.println("Choose the range for random number : ");
System.out.println("1. random number between 1 and 20");
System.out.println("2. random number between 21 and 40");
System.out.println("3. random number between 41 and 60");
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();
switch(choice)
{
case 1:
random1();
break;
case 2:
random2();
break;
case 3:
random3();
break;
default:
System.out.println("Wrong choice");
}
}
}