Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Print elements greater than some value without using booleans

Hey guys,

anyone got any idea how to print element greater than some value from a set without using booleans?

E.g., suppose I have the set x, which includes the elements (1, 4, 6, 3, 5, 2, 9).
Obviously, we can print all the values of x greater than 5 using the following code:
x[x>5] (I code in R, but pretty similar to JAVA)
But this way of coding uses booleans (it uses TRUE, FALSE etc.)

But is there any way to do this using solely integers?
I was thinking about some sort of loop that would start contain the number of elements, and then do
x[c(variable)]

but I don't know really.
Please help?
Are you limited by bitwise operators as well? i.e. can you use (^, |, &, >>, <<, ~)? It would help a bit if you could tell which operators are allowed and which are not.
Not entirely sure why you wouldn't do a simple comparison but anyways, I'll just explain my thought process instead of writing code for a language you don't use. I may be overlooking something but you can't inherently choose when to print or not print something "using solely integers". So I can't really give you what you're looking for. You'd have to check if a number fell within some given parameter (greater than in this case).

I did derive a formula to produce the largest of two numbers a while ago though: 0.5*(abs(a-b)+abs(a+b)) for two given integers, a and b. I don't have the exact proof anymore but it works. I suppose you could apply this to every number in the loop, and set one of the integers to five, you'd still run into the problem of five being produced when it was larger than the other integer. You could filter it but really, any filter function uses some sort of Boolean.
Does this work?

Example.java
Spoiler (Click to View)

Output
Code
PS C:\Users\User\Desktop> javac Example.java
PS C:\Users\User\Desktop> java Example
6
9
PS C:\Users\User\Desktop>
(Feb 10, 2019 05:00 AM)cryptobassboost Wrote:  Hey guys,

anyone got any idea how to print element greater than some value from a set without using booleans?

E.g., suppose I have the set x, which includes the elements (1, 4, 6, 3, 5, 2, 9).
Obviously, we can print all the values of x greater than 5 using the following code:
x[x>5] (I code in R, but pretty similar to JAVA)
But this way of coding uses booleans (it uses TRUE, FALSE etc.)

But is there any way to do this using solely integers?
I was thinking about some sort of loop that would start contain the number of elements, and then do
x[c(variable)]

but I don't know really.
Please help?

thx bro 🤩


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by ShallowMEFeb 17, 2020 07:08 PM 20 524 Feb 17, 2020 07:08 PM
Last Post: 0xDEAD10CC
[C#] by Iera NamhorunJun 21, 2019 06:22 PM 13 346 Jun 21, 2019 06:22 PM
Last Post: Iera Namhorun
[Python] by F.A.S.TApr 15, 2019 01:25 PM 0 78 Apr 15, 2019 01:25 PM
Last Post: F.A.S.T