Question

write a code in jave where you have to Populate even and odd number array. plz...

write a code in jave where you have to Populate even and odd number array.

plz explain it clearly and make sure the code run

Homework Answers

Answer #1
public class MyClass {
    public static void main(String args[]) {
        
        // declaring varaibles
        int n = 20, evenI = 0, oddI = 0;
        
        int[] even = new int[n/2];
        int[] odd = new int[n/2];
        
        // looping from 1 to n
        for(int i=1; i<= n; i++)
        {
            if(i % 2 == 0) // even numbers
            {
                even[evenI] = i;
                evenI++;
            }
            else // odd numbers
            {
                odd[oddI] = i;
                oddI++;
            }
                
        }   
        
    }
}

Please comment if you have doubts. Up vote. Happy Learning!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write Java code that creates an array of primitive integers named odds and stores all odd...
Write Java code that creates an array of primitive integers named odds and stores all odd numbers between -6 and 38 using a for loop. (Your code will populate the array.) Your code should also enable the array’s size to be exactly large enough to store the numbers. (You will not put a number for the size, your code will determine the number.) (5 pt)
Programing lanugaue is C++ Plan and code a menu-driven modular program utilizing an array An input...
Programing lanugaue is C++ Plan and code a menu-driven modular program utilizing an array An input file has an unknown number of numeric values(could be empty too).Read the numbers from the input fileand store even numbers in one arrayand odd numbers in another array.Create menu options to Display count of even numbers, count of odd numbersand the sum values in each array Determine the average of each array Determine the median of each array Sort each array in ascending order(use...
IN JAVA PLEASE write code to MERGESORT an array of user inputted OBJECTS you have two...
IN JAVA PLEASE write code to MERGESORT an array of user inputted OBJECTS you have two different classes in the program being made as objects in the main (Bunny class and Dog Class). ask the user "what kind of animal would you like to sort?" user chooses the type of animal (bunny or dog), then you ask the user how big would you like the array of animals to be (maximum array size = 20)? and then you ask what...
Reversing an array is a common task. One approach copies to a second array in reverse,...
Reversing an array is a common task. One approach copies to a second array in reverse, then copies the second array back to the first. However, to save space, reversing an array without using a second array is sometimes preferable. Write a code in java that reads in an integer representing the length of the array. Then read in and reverse the given array, without using a second array. If the original array's values are 2 5 9 7, the...
C++ Write a function named timesOfLetter that reads an array and returns the number of times...
C++ Write a function named timesOfLetter that reads an array and returns the number of times of each lowercase vowel and each uppercase vowel appear in it using reference parameter. • Write a function named timesOfNumber that reads an array and returns the number of times of each odd number, and each even number appear in it using reference parameter. • Write a function named isChar() that determines the input is alphabetic or not during inputting. • Write a function...
C++ //StudentDataStructure.txt //Student records are stored in a parallel-array Data Structure. Here is the code to...
C++ //StudentDataStructure.txt //Student records are stored in a parallel-array Data Structure. Here is the code to generate and populate Parallel-Array Data Structure: const int NG = 4; //Number of Grades string names[] = {"Amy Adams", "Bob Barr", "Carla Carr", "Dan Dobbs", "Elena Evans" }; int exams[][NG]= { {98,87,93,88}, {78,86,82,91}, {66,71,85,94}, {72,63,77,69}, {91,83,76,60} };    --------------------------------------------------------------------------------- 1 A) Create and Populate a Parallel-Array Data Structure using the code described in "StudentDataStructure.txt". B) Define a Record Data Structure for student records. It...
C++ Write a function that takes in 3 arguments: a sorted array, size of the array,...
C++ Write a function that takes in 3 arguments: a sorted array, size of the array, and an integer number. It should return the position where the integer value is found. In case the number does not exist in that array it should return the index where it should have been if it were present in this sorted array. Use pointer notation of arrays for this question. c++ code
Please, write a loop to print even numbers of an array a with pointers. You can...
Please, write a loop to print even numbers of an array a with pointers. You can use a variable “size” for array size
Can you tell whether a binary number is even or odd only by inspecting the digit...
Can you tell whether a binary number is even or odd only by inspecting the digit in the 1s place? is that always possible for an arbitrary base? if you could, can you explain why or why not? thanks
suppose you have allocated an array of twenty doubles, called values, on the heap. Write the...
suppose you have allocated an array of twenty doubles, called values, on the heap. Write the line of code (including the semicolon) to free up the memory when the array is no longer needed. c code
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT