I'm basically wondering why my conditional statement allows the variable exponent to become 0.0 if a number such as -0.5 is entered by the user. This is my code...
Scanner num2 = new Scanner(System.in);
System.out.println("Enter an integer value for n: ");
int temp = 0;
if(num2.hasNextInt()) {
temp = num2.nextInt();
if(temp >= 1.0 ){
exponent = temp;
}
else {
System.out.println("You have not entered a positive integer value for n.");
exponent();
}
}
return exponent;
The weird part occurs when I assign temp to the nextInt. By doing so, I hope to make the following conditional statement work as intended, (temp has to be greater than or equal to 1 for exponent to be set). However, when I call this function and put in -0.5, the function completes and makes exponent = 0. In this case, my goal is to have an exponent that is greater than or equal to 1. Thanks in advance!