Hack Forums
[Java] Print elements greater than some value without using booleans - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] Print elements greater than some value without using booleans (/showthread.php?tid=5939649)



Print elements greater than some value without using booleans - cryptobassboost - Feb 10, 2019

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?


RE: Print elements greater than some value without using booleans - Moonfall - Feb 10, 2019

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.


RE: Print elements greater than some value without using booleans - seanizcool - Apr 16, 2019

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.


RE: Print elements greater than some value without using booleans - SIM-3991524 - Apr 16, 2019

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>



RE: Print elements greater than some value without using booleans - bluriy - May 20, 2019

(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 🤩