I need to write a program that gets three numbers from the user, then passes those to an overloaded method (I have a double and int).
My question is how do I determine if it’s an int or a double?
To get input I’m doing this:
Scanner input = new Scanner( System.in );
double number1 = input.nextDouble(); // read first double
double number2 = input.nextDouble(); // read second double
double number3 = input.nextDouble(); // read third double
MyMathOps MyMathOps = new MyMathOps();
double result = MyMathOps.maximum( number1, number2, number3 );
System.out.println(result);
But what if they enter an int? I want to be able to determine this, and pass it to the int maximum method.
Just treat all input as
double, since you’re supporting floating point inputs. It doesn’t make sense to useintonly sometimes just because the input happens to be an integer.