Decimal To Binary In Java ISC & ICSE

Program to convert Decimal to Binary

class DecimaltoBinary{//start of class
public void accept(int n){
String str=" ";
while(n!=0){
int r=n%2;
n=n/2;
str=Integer.toString(r)+str;
}
System.out.println("The binary form is "+str);
}}//end of class

OUTPUT--- WHEN INPUT IS 110
The binary form is 1101110 

Comments

Popular posts from this blog

Sort Boundary Elements Of A Matrix

Lucky Number In Java ISC

Program to fill a square matrix of size ‘n*n” in a circular fashion (clockwise) with natural numbers from 1 to n*n, taking ‘n’ as input.