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
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...
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
1. You are given an array of integers, where different integers may have different number of...
1. You are given an array of integers, where different integers may have different number of digits, but the total number of digits over all the integers in the array is n. Show how to sort the array in O(n) time. 2. You are given an array of strings, where different strings may have different numbers of characters, but the total number of characters over all the strings is n. Show how to sort the strings in O(n) time. (Note...
Write an application in Java which includes an algorithm that takes an array of any size,...
Write an application in Java which includes an algorithm that takes an array of any size, selects the high and low integer from the array of integers with each pass and builds a new array of integers by inserting the high and low selection with each pass. Your output should show the original array of integers and the output of each pass on a new line. Note: You can assume all integers are positive, but your code must work for...
Statement 3. If m is an even integer, then 3m + 5 is an odd integer....
Statement 3. If m is an even integer, then 3m + 5 is an odd integer. a. Play with the statement - i.e., Look at/test a few examples. (See if there are any counter-examples.) b. Write a proof of this statement. (Hint: 5 = 4 + 1 = 2(2) + 1) Remark 1. Let's recap some important properties about odd and even that we have seen (in notes and this activity): i. If a and b are even, then ab...
Write a piece of code to find the number of zeros in each byte of an...
Write a piece of code to find the number of zeros in each byte of an array of size 1024 byte stored at addresses starting at 21000H. Store the result of each byte in another array starting at 56000H.
write a loop to print an array a with pointers backwards. You can use a variable...
write a loop to print an array a with pointers backwards. You can use a variable “size” for array size. write you code in C
Your friend has a biased dice, where the probability of rolling an even number is 0.28,...
Your friend has a biased dice, where the probability of rolling an even number is 0.28, and the probability of rolling an odd number is 0.72. Suppose you bet $1 on even. Your friend will pay you $3 if the roll is an even. What is your expected profit (i.e. revenue - cost)?   
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT