Thu Jul 19, 2012 3:53 pm
import java.util.Scanner;
class binaryLoop {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Please enter Integer");
int number = sc.nextInt();
String bin=bin1(number);
System.out.println("Binary number is: "+number+" Decimal number: " + bin);
}
public static String bin1 (int num)
{
int sum=1;
int temp=0;
String bin = "";
if (num==2) ;
while (num!=0)
{
bin=(num%2)+ bin;
num=num/2;
}
return bin;
}
}
Fri Jul 20, 2012 8:49 pm
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.