In: Computer Science
write code to count the number of odd integers in an array of
100 random integers in the range [0,99].
import java.util.Random;
public class OddNumbers{
//code to count the number of odd integers in an array of 100
random integers in range 0-99
public static void main(String []args)
{
Random r=new Random();
int count=0;
int[] arr=new int[100];
for(int i=0;i<100;i++)// loop to generate random numbers in
range 0-99
arr[i]=r.nextInt(100);
for (int i=0;i<100;i++) // loop to check odd test for 100
numbers
{
if(arr[i]%2 != 0)
count++;//to count if a number not divided by
2
}
System.out.println("number of odd numbers="+count);
}//end main
}//end class
//output generated
$javac OddNumbers.java $java -Xmx128M -Xms16M OddNumbers number of odd numbers=53