# Thread: Java - Multiple Values For Int

1. 11
posts
Registered User

## Java - Multiple Values For Int

Is it possible?

Example:
int x = 100, 200, 300;

or

int x =100 || 200 || 300

2. No, it isn't possible. What are you trying to do?

It's possible to have an array of integers:
Code:
`int nums[] = {1,2,3};`

3. 11
posts
Registered User
Originally Posted by Krilnon
No, it isn't possible. What are you trying to do?

It's possible to have an array of integers:
Code:
`int nums[] = {1,2,3};`
I need to make int x equal to three different numbers. And my function must always consider each of those three numbers at the same time.

I need to say this:

x = 100 || 200 || 300
if(y > x) {dothis}
else if(y < x) {dothis}

where y will always be a random number. No, I can't just do x = 100 and y > x. It's important that x equal three numbers.

4. 4,868
posts
Registered User
x can't equal three numbers, think of it this way:
If x = 100 and x = 200, then 100 = 200 which is a contradiction.. therefore x cannot equal 100 and 200.

What is it that you're trying to do?

5. 9
posts
Registered User
Try either an array or just three different variables:

x = 100
z = 200
a = 300
if (y > x || y > z || y > a) {do this}
else {do this}

You can do the same by going through an array with a for loop, but if you only have three ints that's a little much.

The question is whether one of the conditions returning true is sufficient, or if all three conditions must be true. That will change the code a little.

6. Originally Posted by KillCodyDead
I need to make int x equal to three different numbers. And my function must always consider each of those three numbers at the same time.

I need to say this:

x = 100 || 200 || 300
if(y > x) {dothis}
else if(y < x) {dothis}

where y will always be a random number. No, I can't just do x = 100 and y > x. It's important that x equal three numbers.
Your best bet ( like everyone else has mentioned) is to create an array. That is the only way I can think of to compare 1 type with 3 values.

int numbs[] = {100,200,300};

if (y > numbs[0] || y > numbs[1] || y > numbs[2]){
// do this code
}
..... etc

or you can do what battie said and create 3 individual ints.

Whats the purpose of having 3 values in one int?

7. Well, if y is greater than the smallest integer, then technically, doesn't it encompass all of the possible x values?

8. I think your best bet is to put each of the values you want x to take into an array as x and then loop over each of these values and call your function with that value (assuming you don't need to use more than one value at a time - in which case your loop should be within your function and it should take an array as it's parameter).

Most programming languages don't work with vectors - perhaps you're used to working with maple or some other maths package but unfortunately you'll need to work with loops now instead.

Code:
```void test (x) {
if (x > 100) {
// ...
} else if (x < 50) {
// ...
}
}

int i;
int x[] = {10,20,30,40,50,60,70,80,90,100};

for (i=0; i<x.length; i++) {
test(x[i]);
}```
Note that my java sucks.

##### Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•