javascript array
//create an array like so:
var colors = ["red","blue","green"];
//you can loop through an array like this:
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
javascript array
//create an array like so:
var colors = ["red","blue","green"];
//you can loop through an array like this:
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
array
import java.util.Scanner;
public class BooleanPrimes {
public static void main(String[] argh)
{
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a number: ");
int size = scanner.nextInt();
boolean[] boolarray = new boolean[size];
generatorBoolArray(boolarray);
}
public static boolean[] generatorBoolArray(boolean[] boolArr)
{
for (int i = 2; i < boolArr.length; ++i)
{
boolArr[i] = true;
}
return chickIfIndexisPrime(boolArr, boolArr.length);
}
public static boolean[] chickIfIndexisPrime(boolean[] arrIsPrime, int input)
{
int start = 2;
while (start <= input)
{
int i = 2;
boolean isprime = true;
while(i < start )
{
if(start%i == 0) {
isprime = false;
}
++i;
}
if(isprime==true){
for(int j=4; j<arrIsPrime.length ;++j)
{
if(j%start ==0)
{ j=j==start?++j:j;
arrIsPrime[j]=false;
}
}
}
++start;
}
printArray(arrIsPrime);
return arrIsPrime;
}
public static void printArray(boolean[] arr){
System.out.println("Prime numbers: ");
int i=0,j = 0 ;
while(i<arr.length){
if(arr[i]==true){
System.out.print(i+",");
}
++i;
}System.out.println();
while(j<arr.length){
System.out.print("{Index: "+j+" "+arr[j]+"} ");
++j;
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us