b_friendly

write aprogram in java to generate 1 to 100 random integers numbers store in an arry then display all those numbers which are prime numbers

iamthwee 1,547

I don't have my java compiler to hand but I can give you an idea.

you can use the mod operator to find prime numbers

b_friendly

write a java program that will sort three integers the integers are entered from key board and stored in variables num1,num2,num3 respectively.the program sorts the numbers so that num1<=num2<=num3.

iamthwee 1,547

hello are u allowed to use an array for second problem?

b_friendly

hello are u allowed to use an array for second problem?

yes , u can make this program as ur way, and about first one problem, just make the program i will run it with my system, thanx

iamthwee 1,547

ok I will try to hurry.

However, I don't have my compiler so I can not test it directly.

iamthwee 1,547

This is problem one:

``````import java.util.Random;

class Prime
{

public static void main (String[] args)
{
int[] arrays = new int[100];

for (int i=0; i<100; i++)
{
Random generator = new Random();
arrays[i] = generator.nextInt(100);
}

for (int j=0; j<100; j++)
{
double root = Math.sqrt(arrays[j]);
for ( int i = 2; i < = root; i++)
{
if (arrays[j] % i == 0 )

}
System.out.print(arrays[j] + " ");
}
}``````

iamthwee 1,547

``````class Sort
{

public static void main (String[] args)
{
int[] tmp = new int[3];

tmp[0] = 8;
tmp[1] = 3;
tmp[2] = 12;

for (i=0; i<n-1; i++)
{
for (j=0; j<n-1-i; j++)
if (a[j+1] < a[j])
{
tmp = a[j];         /* swap a[j] and a[j+1]      */
a[j] = a[j+1];
a[j+1] = tmp;
}
}

for(int k=0; k<3; k++)
{
System.out.print(tmp[k]+" ");
}

}
}``````

iamthwee 1,547

you may have to put this in a function to work sorrie...

``````public static boolean isPrime (array[j])

double root = Math.sqrt(arrays[j]);
for ( int i = 2; i < = root; i++)
{
if (arrays[j] % i == 0 )
return false;
}
return true;
``````

jwenting 1,649

Don't do other kids' homework for them, it only leads to stupid lazy people gaining diplomas.