My application is supposed to print the smaller value as either int or double, but i don't know how to configure my code to make my application print the smaller number as double or int, depending on the type of value that the user enters.
Ex. user enters 2.5 and 3.5, prints smaller number in double user enters 2 and 3, prints smaller number in int
import java.util.Scanner;
public class SmallerNumber{
public static int smallerNumber(int valOne, int valTwo){
if (valOne < valTwo){
return (valOne);
}
else{
return (valTwo);
}
}
public static double smallerNumber(double valOne, double valTwo){
if (valOne < valTwo){
return (valOne);
}
else{
return (valTwo);
}
}
public static void main(String[]args){
Scanner in = new Scanner(System.in);
System.out.print("Enter first value: ");
int valOne = in.nextInt();
System.out.print("Enter second value: ");
int valTwo = in.nextInt();
int smallerNum = smallerNumber(valOne, valTwo);
System.out.println(smallerNum);
double smallerNum2 = smallerNumber(valOne, valTwo);
System.out.println(smallerNum2);
}
}