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
please help me how to amke this program thanz.
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
please help me how to amke this program thanz.
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
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.
this is my 2nd program please help me i it.
hello are u allowed to use an array for second problem?
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
ok I will try to hurry.
However, I don't have my compiler so I can not test it directly.
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] + " ");
}
}
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]+" ");
}
}
}
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;
Don't do other kids' homework for them, it only leads to stupid lazy people gaining diplomas.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.