KSU CS3401 Assignment Part 2

/*Course: CS3401
 * Section: 01
 * Name: Dalibor Labudovic
 * Professor: Alan Shaw
 * Assignment: Assignment 1 Part 2
*/

package assigment1;

import java.util.Scanner;

public abstract class DBConvert{
public static void main(String[] args)
{
//display into to user
System.out.println("This program will convert a decimal to binary using recursion method.");
System.out.println("Please enter an decimal number to convert: ");
//ask user to input an integer
Scanner userInput = new Scanner(System.in);
int number = userInput.nextInt();
//call method to convert user input number
decimalToBinary(number);
}
// method converts decimal to binary via recursion
public static void decimalToBinary(int value)
{
//condition to end the recursion
if(value > 0)
{
//calling its self until previous condition is met and value is stored per occurance
decimalToBinary(value / 2);
//print results
System.out.print(value % 2);
}
}
}

Comments

Popular posts from this blog

How to clear & format SD card

CS4500 Test 4 Study Guide

Sharepoint List: Days Elapsed or Countdown