5 comments:

  1. import java.util.Scanner;

    class Test1{
    public static void main(String a[]){
    int ar[]=new int[10];
    int i=0,decimal_number,rem=0;
    System.out.print("Enter the decimal number: ");
    Scanner o=new Scanner(System.in);
    decimal_number=o.nextInt();
    while(decimal_number!=0){
    rem=decimal_number%2;
    decimal_number/=2;
    if(i==0){
    ar[i]=rem;
    }
    else{
    for(int j=i;j>0;j--){
    ar[j]=ar[j-1];
    ar[j-1]=rem;
    }
    }
    i++;
    }
    System.out.print("The binary number is: ");
    for(int k=0;k<i;k++)
    System.out.print(ar[k] );

    }
    }


    OUTPUT
    Enter the decimal number: 17
    The binary number is: 10001

    ReplyDelete
  2. import java.util.Scanner;
    class a
    {
    public static void main(String args[])
    {
    Scanner obj=new Scanner(System.in);
    int num;
    num=obj.nextInt();
    int arr[]=new int[];
    int i=0;
    while(num>0)
    {
    arr[i]=num%2;
    num=num/2;
    i++;
    }
    for(i=i-1;i>=0;i--)
    {
    System.out.println(arr[i]);
    }
    }
    }

    ReplyDelete
  3. import java.util.*;
    class DecimalArray
    {
    public static void main(String args[])
    {int Decimal,i=0;
    Scanner scan=new Scanner(System.in);
    System.out.println("Enter the Decimal Value");
    Decimal=scan.nextInt();
    int ar[]=new int[10];
    while(Decimal>0)
    {
    ar[i]=Decimal%2;
    Decimal=Decimal/2;
    i++;
    }
    System.out.print("Binary Number is ");
    for (int j=i-1;j>=0;j--)
    {
    System.out.print(ar[j]);
    }

    }
    }

    ReplyDelete
  4. import java.util.Scanner;
    class DBarray{
    public static void main(String args[]){
    int number,digit=0,remainder=0,i=0;
    int ar[]=new int[10];
    Scanner scan=new Scanner(System.in);
    System.out.println("Enter the number");
    number=scan.nextInt();
    while(number>0)
    {
    remainder=number%2;
    number=number/2;
    ar[i++]=remainder;
    }
    while(i>0){
    System.out.print(ar[--i]);
    }
    }
    }

    ReplyDelete
  5. import java.util.Scanner;

    class Binary{
    public static void main(String ar[]){

    int num,rem=0,i=0;
    System.out.print("Enter the decimal number: ");
    Scanner scan=new Scanner(System.in);
    num=scan.nextInt();
    int a[]=new int[10];
    while(num>0){
    rem=num%2;
    num=num/2;
    a[i]=rem;
    i++;

    }
    System.out.print("The binary number is: ");
    for(int j=i-1;j>=0;j--){
    System.out.print(a[j]);
    }
    }//End of main
    }//End of class

    ReplyDelete