Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.Math;
  3.  
  4. public class Factoring
  5. {
  6. public static void main(String[] args)
  7. {
  8.  
  9. Scanner keyboard = new Scanner (System.in);
  10. long theDivisor;
  11. long theQuotient;
  12.  
  13. while(true)
  14. {
  15. System.out.print("Enter a number >=2: ");
  16. theQuotient = keyboard.nextLong();
  17. theDivisor = 2;
  18.  
  19. if( theQuotient < 2)
  20. {
  21. break ;
  22. }
  23.  
  24. System.out.print(theQuotient + " = ");
  25.  
  26. while( theQuotient > 1)
  27. {
  28. if(theQuotient % theDivisor == 0)
  29. {
  30. System.out.print(theDivisor);
  31. theQuotient = theQuotient / theDivisor;
  32. if(theQuotient > 1)
  33. {
  34. System.out.print(" * ");
  35. }
  36. }
  37. else
  38. {
  39. theDivisor ++;
  40. }
  41. }
  42. System.out.println();
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement