import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int start = sc.nextInt(); // @allcoding1 read in the start of the range
int end = sc.nextInt(); // read in the end of the range
// loop through the range of numbers
for (int i = start; i <= end; i++) {
System.out.println(Integer.toBinaryString(i)); // print the binary representation of the number
}
}
}
Java code
Deloitte exam 5pm
Telegram:- @allcoding1
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int start = sc.nextInt(); // @allcoding1 read in the start of the range
int end = sc.nextInt(); // read in the end of the range
// loop through the range of numbers
for (int i = start; i <= end; i++) {
System.out.println(Integer.toBinaryString(i)); // print the binary representation of the number
}
}
}
Java code
Deloitte exam 5pm
Telegram:- @allcoding1
👍8👎5
def no_consecutive_ones(n: int) -> bool:
bin_n = bin(n)[2:]
for i in range(len(bin_n)-1):
if bin_n[i] == '1' and bin_n[i+1] == '1':
return False
return True
m, n = map(int, input().split())
for i in range(m+1, n):
if no_consecutive_ones(i):
print(bin(i)[2:])
Python
Telegram - @allcoding1
bin_n = bin(n)[2:]
for i in range(len(bin_n)-1):
if bin_n[i] == '1' and bin_n[i+1] == '1':
return False
return True
m, n = map(int, input().split())
for i in range(m+1, n):
if no_consecutive_ones(i):
print(bin(i)[2:])
Python
Telegram - @allcoding1
👍6
👍1
Python
1st line 👇
m, n= map(int, input (). split ())
Deloitte exam 5pm
@allcoding1
https://instagram.com/allcoding1_official?igshid=OGQ2MjdiOTE=
1st line 👇
m, n= map(int, input (). split ())
Deloitte exam 5pm
@allcoding1
https://instagram.com/allcoding1_official?igshid=OGQ2MjdiOTE=
👍9
👍2