Advertisement
d1i2p3a4k5

coa p2

Jan 19th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import java.lang.*;
  2. import java.util.*;
  3. class value
  4. {
  5.     static void convert(int n)
  6.     {
  7.         int i,j,k;
  8.         int a[] = new int[100];
  9.         int rev[] = new int[100];
  10.         for(i=0;n!=0;i++)
  11.         {
  12.             a[i] = n%2;
  13.             n = n/2;
  14.         }
  15.         n = i+1;
  16.         for(i=0;i<n;i++)
  17.         {
  18.             rev[i]=a[n-i-1];
  19.         }
  20.         System.out.println("Binary equivalent is given below");
  21.         for(j=1;j<n;j++)
  22.         {
  23.             System.out.print(rev[j]);
  24.         }
  25.     }  
  26.        
  27.     public static void main (String args[])
  28.     {
  29.         Scanner t = new Scanner(System.in);
  30.         int cov;
  31.         System.out.println("Enter a choice which data has to be entered ");
  32.         System.out.println(" 1.Integer 2.Character ");
  33.         int ch = t.nextInt();
  34.         if(ch==1)
  35.         {
  36.             System.out.println("Enter Integer ");
  37.             int i = t.nextInt();
  38.             convert(i);
  39.         }
  40.         else if(ch==2)
  41.         {
  42.             System.out.println("Enter character ");
  43.             char a = t.next().charAt(0);
  44.             int k = (int)a;
  45.             convert(k);
  46.         }
  47.         else
  48.         System.out.println("Invalid choice ");
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement