// While loop example: find all factors of a given number. import java.util.Scanner; class LoopExample2 { public static void main (String[] args) { Scanner scan = new Scanner(System.in); int number, counter = 1; System.out.print ("Enter a positive number: "); System.out.flush (); number = scan.nextInt(); while (counter <= (number/2)) { if (number%counter == 0) System.out.println (counter + " is a factor of " + number); counter = counter + 1; } System.out.println ("Done."); } }