Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

i need help please

Status
Not open for further replies.

cindyg919

Programmer
Feb 10, 2001
17
US
i am writing a program and i need help with it.
the program is :
write a program that will prompt the user for an integer. the program should then print the binary conversion of the integer on the screen. It should then enter a loop by asking the user if he wants to continue or not. The user should enter 'Y' to continue and 'Q' to quit.

please if you can help me out. Thank-you.
 
Code:
public class BinaryConverter{

   public static void main(String args[]) {
      /* Put your code here */
   }

   public static String convertIntegerToBinary(int i) {
      StringBuffer result = "";
      do {
         int lowOrderBit = (i & 1); // get lowest order bit
         String nextDigit = null;
         if (lowOrderBit == 0)
            nextDigit = "0";
         else
            nextDigit = "1";
         result.append(nextDigit);
         i = i >>> 1; // right shift i one bit
      } while (i != 0);
      return result;
   }
}

If this program is for a class, which I am sure it is, then I suggest you learn what exactly this code block is doing. Also you may want to change the code to use a String instead of a StringBuffer, since you probably don't know what a StringBuffer is. So I left two things for you to do:
1) Change from StringBuffer to String
2) Setup the main and your looping user interface.

If you can't do both of those then I suggest you talk to your teacher about tutoring outside of class.


Wushutwist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top