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 8876339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:11:28+00:00 2026-06-14T19:11:28+00:00

Need to write a java program from pseudo code, I’ve got a bit of

  • 0

Need to write a java program from pseudo code, I’ve got a bit of code written, its not working and I’m not sure if i’ve done it right or not as I simply tried to follow the pseudo code –

  • Read i
  • While i > 0
  • Print the remainder i % 2
  • Set i to i / 2

    import java.util.Scanner;
    
    import java.util.Scanner;
    
    public class InputLoop
    {
        public static void main(String[] args)
        {
            int i = 0;
            Scanner scan = new Scanner(System.in);
            System.out.println("Enter an integer");
            while (!scan.hasNextInt()) // while non-integers are present
            {
                scan.next();
                System.out.println ("Bad input. Enter an integer.");
            }
            while (i>0) // while greater than 0
            {
                int input = scan.nextInt();
                System.out.println (i%2);
                i = (i/2);
            }
    
        }
    }
    
  • 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-14T19:11:29+00:00Added an answer on June 14, 2026 at 7:11 pm

    Frankly speaking, you didn't(Ah missed it earlier) exactly followed the pseudo-code. The pseudo code tells you to read i, whereas you are reading input. That’s one problem.

    Second problem is that, you should read the input outside the while loop where you are doing the processing with the input. That is the 2nd thing you didn’t followed.

    Currently your while loop is: –

        while (i>0) // while greater than 0
        {
            int input = scan.nextInt();
            System.out.println (i%2);
            i = (i/2);
        }
    

    This is read input from user on every iteration which you don’t want.

    So, you need to modify your code a little bit: –

    int i = scan.nextInt();  // Read input outside the while loop
    
    while (i>0) // while greater than 0
    {      
        System.out.println (i%2);
        i = i/2;   // You don't need a bracket here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write one java program which monitors a folder containing excel sheets
I need to write a Perl script that pipes input into a Java program.
I'm trying to write a java program that reads data from an image and
I need to write a program that retrieves information from a database and creates
I need to write a simple terminal-based program that should, Read some text from
I'm pretty new to Java, need to write a program that listen to video
I have to write a standalone java program to decrypt password from file,using Symmetric
I need to write a program to read folder path from stdin and all
I need to write a bash script to compile my java program. I know
I'm trying to write a Java HTTP Proxy Tunnelling program, and I need an

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.