Jump to content

Java Variable Help

SlaughterApollo

I'm trying to make a program for school and i was wondering if it is possible in a while loop or some kind of loop if u can create a unique variable for the each integer value intputted?

Link to comment
Share on other sites

Link to post
Share on other sites

So I'm guessing that you want something like this

 

Press 1 --> Assign variable x

Press 2 --> Assign variable y

Press 3 --> Assign variable z

 

If this is what you're trying to do then you could have a keylistener. Depending on how you're obtaining the input you could do it in different various ways but as long as you receive the input from the keyboard and know what key is pressed then you can use a simple switch statement to proceed with assigning the variables.

int keycodeRelease;switch (keycodeRelease) {    case 45:        // Do something when key 45 is pressed released    case 50:        // Do something else when key 50 is pressed released    break;    default:        // Do something when neither of the given keys are released    break;}
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×