Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8693207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:29:47+00:00 2026-06-13T00:29:47+00:00

This is an assignment question from school: Create a recursive method called toBinary that

  • 0

This is an assignment question from school: Create a recursive method called toBinary that takes a single integer as a parameter and outputs the equivalent in binary.

Here’s my code:

import java.util.*;
class MethodAssign6{
static void toBinary(int a){
    if(a==0){
        System.out.print("theArrayOrStringIWant");
    }
    else{
        System.out.println(a%2);
        toBinary(a/2);
    }
}
public static void main(String[]args){
    toBinary(24);
}
}

As you can see, I have no idea how to create an array to hold all the a%2 values when the question only wants me to have a single integer as a parameter. Anyone please help me I would appreciate very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:29:48+00:00Added an answer on June 13, 2026 at 12:29 am

    I think you’re on the right track—but your current method will print the number out backwards. Try doing the recursive call and then printing:

    static void toBinary(int a){
        if(a!=0) {
            toBinary(a/2);
            System.out.print(a%2);
        }
    }
    

    You could also get a similar effect using a String:

    static String toBinary(int a){
        if(a==0) {
            return "";
        }
        else {
            return toBinary(a/2) + (a%2);
        }
    }
    
    public static void main(String[]args){
        System.out.println(toBinary(24));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an assignment question I received from school. The question says, write a
I've this question from an assignment to create a Store which rent out books,
This is a follow up question from Problem with array assignment I now have
A foreword note that this is for an assignment. A question has already been
After learning from this question that in C++ It is okay to put the
This is my assignment question Create a class with its own operator new. This
I have a linked list question that stems from this homework prompt I am
This is a question corresponds to my uni assignment so I am very sorry
For this assignment I had to create my own string class. I initially wrote
For a school assignment we have to send secure emails coming from a bank

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.