Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Overflow {
- /**
- * What it does
- *
- * for me it finished in about 1 second. Each time I tested it.
- * The time in milliseconds generally said about 1484781388420
- * so that how long it would take to get to Max_INT and crash the loop.
- *
- */
- public static void main(String[] args) {
- int alpha = 0;
- int beta = -100;
- System.out.println(System.currentTimeMillis());
- while(alpha != beta)
- {
- alpha++;
- }
- System.out.println("The Loop has ended.");
- System.out.println(System.currentTimeMillis());
- }
- /**
- * Answering Advanced Experiment:
- *
- * If you add 7 instead of 1 it would still terminate only
- * it would terminate a few seconds faster than adding one each time.
- *
- * Simply because it reaches the max value it can get to as an Int
- * variable faster.
- *
- * as long as you are adding a value it will stop once it reaches
- * Max_INT.
- *
- * if you subtract as soon as you hit -100 it will stop and/or
- * Min_INT; whenever you are subtracting large numbers that pass over -100
- *
- * It would work for Long types except you have give it a lot more time
- * simply because longs can hold more digits than that of ints.
- *
- *
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement