CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Java and JSP (http://www.codingforums.com/forumdisplay.php?f=54)
-   -   help with java code (http://www.codingforums.com/showthread.php?t=25419)

good_omen 08-27-2003 08:31 PM

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

Spookster 08-27-2003 08:49 PM

Yeah you could just use some of the functions built into the API

http://java.sun.com/j2se/1.4.2/docs/...aryString(int)

Jason 08-27-2003 10:08 PM

btw, binary is counted from right to left...
eg:
001 = 1
010 = 2
011 = 3
........


Jason

good_omen 08-28-2003 05:07 PM

thx all, appreciate the help


All times are GMT +1. The time now is 12:05 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.