The result is too big to fit in a long, and it overflows, that's why you get those results. If you need to work with such big number correctly you should use the BigInteger class.
BigInteger int1 = BigInteger.valueOf(9223372036854775807L);
BigInteger int2 = BigInteger.valueOf(9223372036854775807L);
BigInteger n = BigInteger.valueOf(5);
System.out.println(int1.multiply(n));
System.out.println(int1.multiply(int2));
Or if you want the overflow to throw an error you could use Math.multiplyExact(long, long)
long long1 = 9223372036854775807L;
long long2 = 9223372036854775807L;
int n = 5;
System.out.println(Math.multiplyExact(long1, n));
System.out.println(Math.multiplyExact(long1, long2));