Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-27-2003, 08:31 PM   PM User | #1
good_omen
New Coder

 
Join Date: Aug 2003
Location: portland oregon
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
good_omen is an unknown quantity at this point
help with java code

hey 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;
. . . And it goes on . . .

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?

thx everyone
good_omen is offline   Reply With Quote
Old 08-27-2003, 08:49 PM   PM User | #2
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
Yeah you could just use some of the functions built into the API

http://java.sun.com/j2se/1.4.2/docs/...aryString(int)
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 08-27-2003, 10:08 PM   PM User | #3
Jason
Regular Coder

 
Join Date: Feb 2003
Location: California
Posts: 925
Thanks: 0
Thanked 0 Times in 0 Posts
Jason is an unknown quantity at this point
btw, binary is counted from right to left...
eg:
001 = 1
010 = 2
011 = 3
........


Jason
Jason is offline   Reply With Quote
Old 08-28-2003, 05:07 PM   PM User | #4
good_omen
New Coder

 
Join Date: Aug 2003
Location: portland oregon
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
good_omen is an unknown quantity at this point
thx all, appreciate the help
good_omen is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:36 PM.


Advertisement
Log in to turn off these ads.