-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathluckyNumber.java
More file actions
41 lines (40 loc) · 1.05 KB
/
luckyNumber.java
File metadata and controls
41 lines (40 loc) · 1.05 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
package Ishank;
import java.util.Scanner;
public class luckyNumber {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length of array");
int N=sc.nextInt();
int s=N;
int arr[]= new int[N];
System.out.println("Enter the numbers");
for(int x=0;x<N;x++){
arr[x]=sc.nextInt();
}
int c=arr[0], a=1, q=0, d=0;
N=N-1;
arr[0]=0;
for(int x=0;x<(N-1);x++){
if(c>(N))
c=c%(N);
q=0;
for(int y=0;y<c;y++){
d=arr[a];
if(d==0)
y--;
a++;
if(a>s)
a=0;
}
c=d;
arr[a]=0;
--N;
if(N==1)
break;
}
for(int x=0;x<N;x++){
if(arr[x]!=0)
System.out.print("The Lucky Number is "+arr[x]+" at index "+x);
}
}
}