Why does the below code not pass test cases when integer datatype is used?
public class Main
public static void main(String args) throws IOException
Scanner in=new Scanner(System.in);
// //ps: this is the health of the monster.
// //for us to win the game, the monster's health points gotto be 0 or lesser.
//y represents gain of points by monster, x=loss by monster..;,
//ideally for us to win the monster's loss should be more ...otherwise we are losing, we wont defeat the bad guy.
long h = in.nextLong();
long x = in.nextLong();
long y = in.nextLong();
can you link the full problem? I would assume the numbers read are too big to be stored inside integers.
PLEASE CHECK out the above link!
you can print the min and max values of both int and long in java like this:
You do not have to learn these values though. It is easier to keep in mind that an int has 32 bits and a long has 64 bits worth of storage. This corresponds to a size of 2³² and 2⁶⁴ respectively.
The problem states you need to be able to store 10¹⁸.
10³ ≈ 2¹⁰ =>10¹⁸ ≈ 2⁶⁰ => you need long