I'm trying to determine how many times the number four appears in a sequence of numbers. There is a lower bound and upper bound (inclusive) that the user can determine. My code so far only counts the number of times the number 4 occurs if the range is set 40-49-- the resulting output is 10, however the actual value should be 11 because 44 has two 4's. In addition, the output for a range of 1-10 should be 1 but instead I get a value of zero? Am I not properly checking for the occurrence of 4? I'm taking into account the difference places (one's, tenths, hundredths place).
Scanner scan = new Scanner(System.in);
int count = 0;
int i;
System.out.println("Enter the lower range: ");
int lower = scan.nextInt();
System.out.println("Enter the upper range: ");
int upper = scan.nextInt();
if (lower > upper) {
System.out.println("Bad input");
}
for (i = lower; i <= upper; i++) {
if (lower * 0.01 == 4) {
count++;
} else if (lower * .1 == 4) {
count++;
} else if (lower * 1 == 4) {
count++;
}
}
System.out.println("Result: " + count);