diff --git a/Java/Algorithm/Threads.java b/Java/Algorithm/Threads.java new file mode 100644 index 0000000..1c6a62f --- /dev/null +++ b/Java/Algorithm/Threads.java @@ -0,0 +1,67 @@ + +import java.util.Scanner; + +import heavy.threads; +import java.util.Scanner; +public class Threads { + + public static void main (String args[]) throws InterruptedException + { + Scanner sc=new Scanner(System.in); + myThread1 t1=new myThread1(); //creating a object of class myThread1 + myThread2 t2=new myThread2(); + myThread3 t3=new myThread3(); + t1.run(); //invoking run method in class muThread1 + t1.sleep(4000); //putting for sleep 4 sec + t2.run(); + t2.sleep(2000); + t3.run(); + + } + + +} +class myThread1 extends Thread +{ + public void run() + { + + System.out.println("enter any number"); + Scanner sc = new Scanner(System.in); + int a=sc.nextInt(); + int k=fib(a); + System.out.println(k); + + } + public static int fib(int n) + { + if (n <= 1) + { + return n; + } + else + { + return fib(n-1) + fib(n-2); + } + } +} +class myThread2 extends Thread +{ + public void run() + { + for(int i=100;i<=150;i++) + { + System.out.println(i); + } + } +} +class myThread3 extends Thread +{ + public void run() + { + for(int i=1;i<=10;i++) + { + System.out.println(i); + } + } +} diff --git a/Python/BinaryNumber.py b/Python/BinaryNumber.py new file mode 100644 index 0000000..116cf8a --- /dev/null +++ b/Python/BinaryNumber.py @@ -0,0 +1,55 @@ +Given a base-10 integer,n, convert it to binary (base-2). Then find and print the base-10 integer denoting the maximum number of consecutive 1's in n's binary representation. When working with different bases, it is common to show the base as a subscript. + +Example + +n=125 + +The binary representation of 125 is1111101 . In base 10 , there are 5 and 1 consecutive ones in two groups. Print the maximum, . + +Input Format + +A single integer,n . + +1<=n<=10^6 + +Output Format + +Print a single base-10 integer that denotes the maximum number of consecutive 1's in the binary representation of n. + +Sample input +------- + 5 +Sample output + ------ + 1 + + Sample input +------- + 13 + Sample output + ------ + 2 + + + Ans -Python + ----------- + #here we need to read a number and find it binary then we need to print the number of maximum ajacent 1 is there + #i converted it into binary using bin fuction and made it into string and then made an list with spilt via '0', Now we just need print the length of maximum valued binary number + + +import math +import os +import random +import re +import sys +def fun(n): + s="".join(bin(n)) + s=s.split('b') + p="".join(s[1]) + p=p.split('0') + print(len(max(p))) + + +if __name__ == '__main__': + n = int(input().strip()) + fun(n)