Java program to find all binary equivalent of all numbers in given range.


import java.util.Scanner;
public class BinaryNumber
{
public static void main(String[] args)
{
int l,h,i,num;
Scanner sc=new Scanner(System.in);
System.out.print("Enter lower range:");
l=sc.nextInt();
System.out.print("Enter Higher range:");
h=sc.nextInt();
System.out.println("Binary number between "+l+" and "+h+" are:=>");
for(i=l;i<=h;i++)
{
  int B=0,base=1,rem=0;
  num=i;
  while(num>0)
  {
    rem=num%2;
    B=B+rem*base;
    num=num/2;
    base=base*10;
  }
  System.out.print("\nBinary equivalent of "+i+" ==>"+B);
}
sc.close();
}
}


*** Input && Output ***



Post a Comment

0 Comments