// Counting.java // Bob Myers // // A typical kind of for-loop algorithm import java.util.Scanner; class Counting { public static void main(String[] args) { Scanner s = new Scanner(System.in); int value; System.out.print("Enter an integer: "); value = s.nextInt(); int counter = 0; // initialize a counter variable int i; for (i = 1; i <= value; i++) { if (i % 5 == 0) // if the index is divisible by 5 counter++; // increment the counter } System.out.println("There are " + counter + " numbers divisible by 5 in the range 1 through " + value); } }