can anyone convert me this below program first into a new
program using the while loop. And then the program using the do
while loop.
// This class will test the performance of the for loop
public class IterativeStatements {
public static void main(String[] args) {
// Save the start time.
long timeStarted = System.currentTimeMillis();
// Create an array of integers, and populated
int[] numbers = new int[1000000];
for(int i=0; i<numbers.length; i++)
numbers[i] = i;
for(int i=2; i<numbers.length; i++)
if(numbers[i]!=0)
for(int j=i*2; j<numbers.length; j+=i)
numbers[j] = 0;
// Program finished
long timeFinished = System.currentTimeMillis();
System.out.println("Time taken in milli seconds: "
+(timeFinished-timeStarted));
/*
* Display only those which are not zero,
* therefore the prime numbers
*/
for(int i=0; i<numbers.length; i++)
if(numbers[i]!=0)
System.out.println(numbers[i]);
}
}