0
if (liquidInOunces > 1000000000) {
  //Display error message.
     System.out.println("Amount must not exceed 1,000,000,000.");
     return;

If i use a 10 digit number it displays the error message as wanted. If i use a number over 10 digits i get a java error. I need this to display the error message no matter how long the user input is.

  • What is `liquidInOunces` type? What's the range for that type? – Andrew S Sep 07 '17 at 18:40
  • It sounds like your real problem is the "java error", not the code you posted. `int` can only hold up to 2147483647, you probably need to change `liquidInOunces` to a `long`. – Sean Van Gorder Sep 07 '17 at 18:44
  • try this instead -> `if(liquidInOunces.compareTo(new BigInteger("1000000000")) > 0){ ... }` also make sure you accomodate the type of input you're expecting i.e now you should have something like `Scanner sc = new Scanner(System.in); BigInteger liquidInOunces = sc.nextBigInteger();` – Ousmane D. Sep 07 '17 at 18:45
  • "If i use a number over 10 digits i get a java error" if you don't add any suffix then number will be treated as `int` representation, but maximal int value is `2147483647` (10 digits). Adding more digit will exceed that value. You can explicitly create number of type like `long` which is 64 bit, so its max value is `9223372036854775807`. To do that end your number with `L` or `l` (but usually we avoid `l` suffix because some fonts print it in a way similar to `1` which causes a lot of confusion). – Pshemo Sep 07 '17 at 18:46

0 Answers0