Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-06-2007, 01:19 AM
Member
 
Join Date: Jul 2007
Posts: 40
trill is on a distinguished road
Help with gigantamous switch statement
Hi, I have a question with some code. I am making a simple cheesy little program that changes any int that a user inputs into that numbers binary value. Here is a sample of my code:

Code:
int number System.out.print("Type an int from 1 to 99: "); number = InputOutput.getInt(); switch (number) { case 1: System.out.println("10000000"); break; case 2: System.out.println("01000000"); break; case 3: System.out.println("11000000"); break;
Is there any way to make this code easier or should i say shorter to write instead of one gigantamous switch statement? and one last thing, if i asked the user if they wanted to type another int, and they said yes, how would i loop the program?
Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-06-2007, 06:52 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Is there any way to make this code easier or should i say shorter to write instead of one gigantamous switch statement?
The way you have it looks okay. You could try the convenience method shown below.
how would i loop the program
Try this (pseudocode):
Code:
do { System.out.print("Type an int from 1 to 99: "); int number = InputOutput.getInt(); String binary = Integer.toBinaryString(number); System.out.println("binary = " + binary); System.out.println("Want more? \"y\" \"n\""); String s = InputOutput.readLine(); } while(s.equals("y"));
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-06-2007, 10:11 AM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
Just found out that there was a toBinaryString(), thanks hardwired
Btw, this statement
Code:
String s = InputOutput.readLine();
U two used it, is there exist an InputOutput class or is it just ur custom created one?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Method in a Switch Statement cart1443 New To Java 6 03-14-2008 05:48 AM
Switch Statement Help bluegreen7hi New To Java 6 02-06-2008 07:16 AM
Switch statement to display the name of the month Java Tip Java Tips 0 01-04-2008 11:32 AM
Problem with a switch statement in Java baltimore New To Java 2 08-02-2007 06:43 AM
Statement or Prepared Statement ? paty Database 3 08-01-2007 06:45 PM


All times are GMT +3. The time now is 10:25 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org