My issue is I am asking a user to input a value that is a positive integer. I have made sure that they cannot input a negative integer or zero but I am not sure how to make sure they cannot input a decimal.
package java1;
public class Problem3NPlus1 {
public static void main(String[] args) {
int givenInt;
int givenIntMod;
System.out.println("Provide a positive integer: ");
givenInt = TextIO.getlnInt();
while (givenInt <= 0 || *IF GIVENINT IS A DECIMAL? ) {
System.out.println("That is not a positive integer, try again: ");
givenInt = TextIO.getlnInt();
}
if (givenInt > 0) {
while (givenInt != 1) {
if (givenInt % 2 == 0) {
givenIntMod = (givenInt / 2);
}
else {
givenIntMod = ((givenInt * 3) + 1);
}
System.out.println(givenIntMod);
givenInt = givenIntMod;
}
}
}
}
11.001you will only read 11. Is that good enough?