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

  • SEARCH
  • Home
  • 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 8584711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:50:09+00:00 2026-06-11T21:50:09+00:00

I am making a program that is converting from decimal to binary, octal, and

  • 0

I am making a program that is converting from decimal to binary, octal, and hexadecimal. I am only focusing on the decimal to binary part in this so far. My problems are that the binary when I ask it to convert up to said number print them vertically not horizontally like 010. Also my while statement does not stop exacution if the y input is greater than 1024, which is the highest value I want to be able to be accepted.

import java.util.Scanner;

public class DNS
{
    public static void main(String[] args)
    {
        int y;
        Scanner input = new Scanner( System.in);
    do
    {   
        System.out.println("java DisplayNumberSystems");
        System.out.println("Enter a decimal value to display to: ");
        y = input.nextInt();

        for(int x=0; x <=y; x++)
        {
            convertToBinary(x);
        }
    }
    while(y <=1024);    

    }

    public static void convertToBinary(int x)
    {
        if(x >0)
        {
            convertToBinary(x/2);
            System.out.print(x%2 + " ");

        }
        System.out.println("");
    }

}
  • 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-11T21:50:11+00:00Added an answer on June 11, 2026 at 9:50 pm

    remove System.out.println(""); from public static void convertToBinary(int x)
    you will be able to print horizontally

    and change your do-while to simple while like this

        int y;
        Scanner input = new Scanner( System.in);
        System.out.println("java DisplayNumberSystems");
        System.out.println("Enter a decimal value to display to: ");
        y = input.nextInt();
    
        while(y <=1024)
    {   
    
        for(int x=0; x <=y; x++)
        {
            convertToBinary(x);
        }
    }
    

    you were checking if y<=1024 after calling convertToBinary() method. you have check if y<=1024 before making a call to convertToBinary() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been making a program that creates multiple CSV's from another source CSV
I'm making a program that asks for an integer from the user, it then
I'm making a program that, in part, rolls four dice and subtracts the lowest
I'm making a program that connects to a website and downloads XML from it.
I am making a program that takes input from files that I have called
I am making a program that reads and stores data from Windows EventLog files
I am making a program that opens and reads a file. This is my
I am making a program that loads videos from a server and then saves
I'm making a program that listens for commands both from a looping raw_input and
I'm making a program that will display a few images from a directory beside

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.