/*
Online Java - IDE, Code Editor, Compiler

Online Java is a quick and easy tool that helps you to build, compile, test your programs online.
*/
import java.util.Scanner;

public class Main
{
    public static void main(String[] args) {
        
        int j=0;
        
        
        int binary[] = new int[31];   //This is to define 30 bit array to hold binary value. Maximum value is over 2 billion.
                                      // This is Java's limitation.
        
        int i;   //counter
        //int num;
        
        //do{
            
        Scanner reader = new Scanner(System.in);  // Reading from System.in
        System.out.println("Enter a number no larger than 2,000,000,000: ");
        int num = reader.nextInt(); // Scans the next token of the input as an int.
        //once finished
        reader.close();
        //} while(num<2000000000);
        
        
        int length = binary.length;
        System.out.println("length: "  + length);
        
        System.out.println("*** This program will convert decimal into binary");
        
        //Execute a for loop to check modulus (i.e no remainder)
        
        //execute a loop from 0 to 8. This is the powers used in base 2 system to allow representation from 1 to 128.
        
        for (i=length-1; i>=0; i--)
        {
            
                int divisor = (int)(Math.pow(2,i));
                System.out.println("divisor is:" + divisor);
                
                if (num - divisor >=0)
        {  
           
            binary[(length-1)-i] = 1;
            num=num-divisor;
          
        }
                
            }
    
    //This will check if there are 3 consecutive 1's as per initial problem
    // Need to ensure that least significant bit is not compared to right handside.
    //Also need to ensure most significant bit is not compared to left hand side
    
           for (i=length-1; i>=0; i--)
     {
         if (i==length-1)            //this is to check for 3 consecutive 1's with the MSB
         {
             if (binary[i]==1 && binary[i-1]==1 && binary[i-2]==1 )
             {
                 System.out.println("Three consecutive 1s found");
                 break;
                 
             }
         }
         
         if (i==0)                 //this is to check for 3 consecutive 1's with the LSB
         {
             if (binary[i]==1 && binary[i+1]==1 && binary[i+2]==1 )
             {
                 System.out.println("Three consecutive 1s found");
                 break;
                 
             }
         }
             
         // this is to check all other bits against adjacent bits for 1s
         if (binary[i]==1 && binary[i+1]==1 && binary[i-1]==1 )
         {
         
         System.out.println("Three consecutive 1s found");
         break;
         }
         
         
     }
        
      }    
    
}