-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheck01.java
More file actions
58 lines (38 loc) · 851 Bytes
/
Check01.java
File metadata and controls
58 lines (38 loc) · 851 Bytes
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
// wap to check which position haing 0 or 1
import java.util.*;
public class Check01
{
public static void main(String[] args )
{
int i=0,j,n,p;
Scanner sc=new Scanner(System.in);
System.out.println("Enter Position U Want to Check:");
p=sc.nextInt();
System.out.println("Enter trhe decimal number= ");
n=sc.nextInt();
int bin[] = new int[20];
if(n>=p)
{
while(n>0)
{
bin[i]=n%2;
n=n/2;
i++;
}
for(i=(i-1);i>=0;i--)
{
System.out.print( " "+bin[i]);
}
}
else
//System.out.println("Please Enter A valid Number: ");
System.out.println("");
System.out.print(" Found at "+p+" Position = ");
if(bin[p-1]==1)
{
System.out.print(" 1 ");
}
else
System.out.println("0");
}
}