Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
import java.util.ArrayList;
public class Demo {
public static void main(String[] args) {
ArrayList<Integer>arrList = new ArrayList<Integer>();
arrList.add(100);
arrList.add(200);
arrList.add(300);
arrList.add(400);
arrList.add(500);
arrList.add(600);
arrList.add(700);
arrList.add(800);
arrList.add(900);
arrList.add(1000);
final int[] arr = new int[arrList.size()];
int index = 0;
for (final Integer value : arrList) {
arr[index++] = value;
}
System.out.println("Elements of int array...");
for (Integer i : arr) {
System.out.println(i);
}
}
}
public class Demo {
public static void main(String[] args) {
// set a value to check
int val = 30;
boolean[] isprime = new boolean[val + 1];
for (int i = 0; i <= val; i++)
isprime[i] = true;
// 0 and 1 is not prime
isprime[0] = false;
isprime[1] = false;
int n = (int) Math.ceil(Math.sqrt(val));
for (int i = 0; i <= n; i++) {
if (isprime[i])
for (int j = 2 * i; j <= val; j = j + i)
// not prime
isprime[j] = false;
}
int myPrime;
for (myPrime = val; !isprime[myPrime]; myPrime--)
; // empty loop body
System.out.println("Largest prime less than or equal to " + val + " = " + myPrime);
}
}