Welcome to Dream.In.Code
Become a Java Expert!

Join 136,896 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,730 people online right now. Registration is fast and FREE... Join Now!




recursive method

 
Reply to this topicStart new topic

recursive method, a recursive method that is able to convert a decinal number to differe

negotiator
24 Mar, 2008 - 03:57 AM
Post #1

New D.I.C Head
*

Joined: 24 Mar, 2008
Posts: 2

java

import java.util.*;

public class DifferBases
{
static Scanner negotiator= new Scanner(System.in);
public static void main(String[] negotiator)
{
int num;
int base;



System.out.print("enter a number int decimal");
num=negotiator.nextInt();
System.out.println();


System.out.print("enter a Base number");
base=negotiator.nextInt();
System.out.println();



System.out.print("enter a number int decimal");
DiffBase=(num, base);
System.out.println("binary");

}
public static void DiffBase(int num,int base)
if(num>0)
{
DiffBase(num/base,base);
System.out.print(num % base);
}
}

public static void DiffBase(int num,int base)
int base=8;
if(num>0)
{
DiffBase(num/base,base);
System.out.print(num % base);
}

public static void DiffBase(int num,int base)
int base=8;
if(num>0)
{
DiffBase(num/base,base);
System.out.print(num % base);
}

public static void DiffBase(int num,int base)
int base=16;
if(num>0)
{
DiffBase(num/base,base);
System.out.print(num % base);
}


} }

BY THE WAY THIS PROGRAM DOES NOT COMPILE BUT I KNOW IT SHOULD BE SOMETHING THAT KIND

This post has been edited by 1lacca: 24 Mar, 2008 - 04:24 AM
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Recursive Method
24 Mar, 2008 - 04:29 AM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 11 times
My Contributions
Please post the compiler error you receive, and use code tags code.gif
Btw, welcome to DIC!
User is offlineProfile CardPM
+Quote Post

potator
RE: Recursive Method
24 Mar, 2008 - 08:08 PM
Post #3

D.I.C Head
Group Icon

Joined: 2 Dec, 2007
Posts: 78



Thanked: 1 times
Dream Kudos: 175
My Contributions
This is a method I designed for your cause:

CODE

public static String changeBase(int decimal, int base){
    if(decimal != 0)
        return changeBase((decimal / base), base) + new Integer(decimal % base).toString();
    return "";
}


You can incorporate it with a main method or whatnot. I assumed you used an algorithm similar to the one found here. If you want to understand what it is doing, or if you just want to understand recursion in general, you should check out the recursion tutorial. It was written by a pretty cool guy who doesn't afraid of anything.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 09:27PM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month