Guest User

Untitled

a guest
Dec 11th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FactorRange
  4. {
  5. public static void main(String[] args)
  6. {
  7. Scanner scan = new Scanner(System.in);
  8. int a, b, c, min, max;
  9.  
  10. //Get user input.
  11. 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: ");
  12. a = scan.nextInt();
  13. b = scan.nextInt();
  14. c = scan.nextInt();
  15.  
  16. //Discover which of the range values is largest.
  17. if(a > b) {
  18. min = b;
  19. max = a;
  20. } else {
  21. min = a;
  22. max = b;
  23. }
  24.  
  25. //Find factors.
  26. for(int i = min; i <= max; i++)
  27. if(c % i == 0)
  28. System.out.println(i + " is a factor of " + c);
  29.  
  30. }
  31. }
Add Comment
Please, Sign In to add comment