Array Loop Example
From Java Example Source Code
Contents |
[edit] Overview - Array Loop Example
This is a Java example program.
[edit] Java Source Code
- Package: example.array
- File: TimeArray.java
package example.array; public class TimeArray { public static void main(String args[]) { System.out.println("Integer.MAX_VALUE="+Integer.MAX_VALUE); long startTime = System.currentTimeMillis(); for (int i = 0, n = Integer.MAX_VALUE; i < n; i++) { ; } long midTime = System.currentTimeMillis(); for (int i = Integer.MAX_VALUE - 1; i >= 0; i--) { ; } long endTime = System.currentTimeMillis(); System.out.println("Increasing: " + (midTime - startTime)); System.out.println("Decreasing: " + (endTime - midTime)); } }
[edit] What Result You Can Get
Run this program, you will get:
Integer.MAX_VALUE=2147483647 Increasing: 4427 Decreasing: 4446
[edit] Required External Libraries and/or Files for this Java Example
Need nothing.
[edit] How to Run this Java Example Program
We recommend running this Java example program with Eclipse.
For assistance in working with Eclipse, please see How to Run Java Program with Eclipse.
It's fairly easy.
[edit] Question & Answer
Any question?
Click edit and post your question or answer here.
