Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. public class Overflow {
  2.  
  3. /**
  4. * What it does
  5. *
  6. * for me it finished in about 1 second. Each time I tested it.
  7. * The time in milliseconds generally said about 1484781388420
  8. * so that how long it would take to get to Max_INT and crash the loop.
  9. *
  10. */
  11.  
  12. public static void main(String[] args) {
  13.  
  14. int alpha = 0;
  15. int beta = -100;
  16. System.out.println(System.currentTimeMillis());
  17. while(alpha != beta)
  18. {
  19. alpha++;
  20. }
  21. System.out.println("The Loop has ended.");
  22. System.out.println(System.currentTimeMillis());
  23. }
  24. /**
  25. * Answering Advanced Experiment:
  26. *
  27. * If you add 7 instead of 1 it would still terminate only
  28. * it would terminate a few seconds faster than adding one each time.
  29. *
  30. * Simply because it reaches the max value it can get to as an Int
  31. * variable faster.
  32. *
  33. * as long as you are adding a value it will stop once it reaches
  34. * Max_INT.
  35. *
  36. * if you subtract as soon as you hit -100 it will stop and/or
  37. * Min_INT; whenever you are subtracting large numbers that pass over -100
  38. *
  39. * It would work for Long types except you have give it a lot more time
  40. * simply because longs can hold more digits than that of ints.
  41. *
  42. *
  43. */
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement