/* This is the solution for the first In- Class- Exercise on 02/16/2016 * You were required to accept a positive integer from the user and print all its factors. * Sample Run: * Enter a number: 48 * 1 2 3 4 6 8 12 16 24 48 */ import java.util.Scanner; class Factor { public static void main (String [] args) { Scanner input = new Scanner (System.in); System.out.println("Enter a number: "); int number = input.nextInt(); // We know the number is going to be a positive integer /* We run a loop from 1 till the number */ for(int i=1;i<=number;i++) { // if the current number, i, divides the number without a remainder, it is a factor. // We just print the factor, since we don't need to store anywhere. if(number % i == 0) System.out.printl(i+ "\t"); } // This newline is just to display the prompt cleanly. System.out.println(); } }