DecimalToBinary

DecimalToBinary - { int decimalNum; int base; base = 2;

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//********************************************************* // Author: D.S. Malik // // Recursion: Program - Decimal to Binary // This program uses recursion to find the binary // representation of a nonnegative integer. //********************************************************* / import java.util.*; i public class DecimalToBinary { static Scanner console = new Scanner(System.in); public static void main(String[] args)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { int decimalNum; int base; base = 2; System.out.print("Enter a positive integer in " + "decimal: "); decimalNum = console.nextInt(); System.out.println(); System.out.print("Decimal " + decimalNum + " = "); decToBin(decimalNum, base); System.out.println(" binary"); } public static void decToBin(int num, int base) { if (num > 0) { decToBin(num / base, base); System.out.print(num % base); } } }...
View Full Document

This note was uploaded on 06/17/2011 for the course COMP 2301 taught by Professor Staff during the Spring '10 term at Kennesaw.

Ask a homework question - tutors are online