Skip to content
Advertisement

Tag: int

Integer parameters formula returns integer

Code below makes foo value as -1149239296 i. e. integer value which is out of bounds: Seems like Java takes type of first parameter and tryes to return formula’s result with that type. Where in Java specification one can read that story? I made such suggestion cause actually returns sets long value to foo. Answer For this case, casting any

How to Convert Int to Unsigned Byte and Back

I need to convert a number into an unsigned byte. The number is always less than or equal to 255, and so it will fit in one byte. I also need to convert that byte back into that number. How would I do that in Java? I’ve tried several ways and none work. Here’s what I’m trying to do now:

Java: for loop, incompatible types

I’m trying to run this for loop; However every time I try to compile I get an error stating ‘incompatible types – found int but expected boolean’ I can’t work out what I’m doing wrong! Answer the second statement: grid[0].length is an integer. The second statement in a for loop is a condition statement and needs to be a boolean.

Java Array Sort descending?

Is there any EASY way to sort an array in descending order like how they have a sort in ascending order in the Arrays class? Or do I have to stop being lazy and do this myself :[ Answer You could use this to sort all kind of Objects Arrays.sort() cannot be used directly to sort primitive arrays in descending

How do I convert from int to Long in Java?

I keep finding both on here and Google people having troubles going from long to int and not the other way around. Yet I’m sure I’m not the only one that has run into this scenario before going from int to Long. The only other answers I’ve found were “Just set it as Long in the first place” which really

Advertisement