Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class FactorRange
- {
- public static void main(String[] args)
- {
- Scanner scan = new Scanner(System.in);
- int a, b, c, min, max;
- //Get user input.
- System.out.println("Please enter three numbers. The first two will determine the range, and the third will be what you're discovering factors of: ");
- a = scan.nextInt();
- b = scan.nextInt();
- c = scan.nextInt();
- //Discover which of the range values is largest.
- if(a > b) {
- min = b;
- max = a;
- } else {
- min = a;
- max = b;
- }
- //Find factors.
- for(int i = min; i <= max; i++)
- if(c % i == 0)
- System.out.println(i + " is a factor of " + c);
- }
- }
Add Comment
Please, Sign In to add comment