1 answer

Implement a Paritylterator for an ArrayList such that when the arraylist has odd number of items,...

Question:

Implement a Paritylterator for an ArrayList such that when the arraylist has odd number of items, it will only return the 1st, 3rd, 5th, items and if the arraylist has even number of items it will return the 2nd, 4th, 6th... items.

Implement a Paritylterator for an ArrayList such that when the arraylist has odd number of items, it will only return the 1st, 3rd, 5th, items and if the arraylist has even number of items it will return the 2nd, 4th, 6th... items.

Answers

import java.util.ArrayList;

public class ParityIterator {

public static <T> void parity(ArrayList<T> list)

{

int size=list.size();

if(size%2==0)

{

for(int i=0;i<size;i+=2)

System.out.println(list.get(i));

}

else

{

for(int i=1;i<size;i+=2)

System.out.println(list.get(i));

}

}

public static void main(String[] args) {

ArrayList<String> s=new ArrayList<String>();

ArrayList<String> l=new ArrayList<String>();

s.add("A");

s.add("B");

s.add("C");

s.add("D");

s.add("E");

s.add("F");

l.add("A");

l.add("B");

l.add("C");

l.add("D");

l.add("E");

parity(s);

parity(l);

}

}

Please do give a thumbs up and leave a comment if you have any doubt.

.

Similar Solved Questions

1 answer
Which transition in a hydrogen atom requires the largest absorption of energy? a) n1 = 2...
Which transition in a hydrogen atom requires the largest absorption of energy? a) n1 = 2 to n2 = 3 b) n1 = 6 to n2 = 3 c) n1 = 3 to n2 = 1 d) n1 = 1 to n2 = 3...
2 answers
And quantitative tests on a wide variety of specimens. Multiple Choice Instructions: Circle the letter of...
and quantitative tests on a wide variety of specimens. Multiple Choice Instructions: Circle the letter of the best answer to each question based on the information you learned in this chapter. 1. When should modifier -90 be reported? A. A lab test is performed in the office B. A specimen is sent to ...
1 answer
Please answer number two! Thank you Problem 2 The Wood Company has the following costs: Category...
please answer number two! Thank you Problem 2 The Wood Company has the following costs: Category Cost Cost Rent Utilities Insurance Payment Period Monthly Monthly Quarterly $1,500 500 900 Property Taxes Annually 3,600 Wood Sawing Labor Price Per Shelf Per Shelf Per Shelf Per Shelf 3.00 1.00 0.75 15....
1 answer
I need the following done in MASM (Assmebly or ASM) This program must use Irvine Library and the outline for the code is...
I need the following done in MASM (Assmebly or ASM) This program must use Irvine Library and the outline for the code is below (Kip irvine) Write an assembly language program to input a string from the user. Your program should do these two things: 1. count and display the number of words in the use...
1 answer
In this problem, p is in dollars and x is the number of units. Suppose the...
In this problem, p is in dollars and x is the number of units. Suppose the demand function for a product is p and the supply function is p = 1 + 0.2x. (x + 1) Find the equilibrium quantity. X1 - Find the equilibrium point. Find the consumer's surplus under pure competition. (Round your answer to...
1 answer
Anyone help me those questions? thx!! Question 1 dz , + )2, where a1, a2, and...
anyone help me those questions? thx!! Question 1 dz , + )2, where a1, a2, and a3 are constants. Find dq. Not yet answered Let-(o)-1(a Points out of 1 Select one Flag question a. 3q Question Not yet answered Points out of 1 Let w(x,y) b1 + b2x + bay + b,xy, where x and y are variables and b, are all ...
1 answer
Can someone help with the blue reader project, please? I have the journal entries I need...
can someone help with the blue reader project, please? I have the journal entries I need help with journal ledger and trial balance so I can I do the financial statements. thanks can someone help me the ledger and trial balance please, I posted all the information about the pictu...
1 answer
Beaker 2 19 490 70 25.00m addedl 25. beaher APer evaprao Bt 62 50.1258 q A....
beaker 2 19 490 70 25.00m addedl 25. beaher APer evaprao Bt 62 50.1258 q A. Determine 4ho mass ol tha tota I dissolved solids n arams far eadn sample Derermine sthe mass ol Hho solids in milliarams Pach sample...
1 answer
(a) worked out incorrectly; or (b) worked out correctly but using a method not specified in...
(a) worked out incorrectly; or (b) worked out correctly but using a method not specified in the problem statement; or (c) not solved completely, but the answer is stated with inadequate or no work shown, EVEN IF THE FINAL ANSWER IS CORRECT. 2) Write the nth term of the sequence whose first several t...
3 answers
A spring hangs ( unstretched) from a support. A 300 gram mass is suspended from the...
A spring hangs ( unstretched) from a support. A 300 gram mass is suspended from the spring and allowed to reach equilibrium. If the mass is pulled below this equilibrium position and released, what is its period of oscillation? (the spring stretches to 30.0 cm) Please, show me....
1 answer
Calculate the percentage of water of hydration in barium chloride crystals (the atomic weight of Ba is about 137.4 g/mol)?
Calculate the percentage of water of hydration in barium chloride crystals (the atomic weight of Ba is about 137.4 g/mol)?...
1 answer
How do sodium-potassium pumps support the efficient functioning of cells?
How do sodium-potassium pumps support the efficient functioning of cells?...
1 answer
Problem 12 (2 points) Joe runs an exotic animal farm. The output his firm produces is...
Problem 12 (2 points) Joe runs an exotic animal farm. The output his firm produces is ticket sales, and the inputs to production are the number of tigers (T) at the farm, the number of lions (L) at the farm, and the number of wolves (W) at the farm. Each tiger generates 2 ticket sales, each lion gen...
1 answer
C. The error rate with the blood test is greater than the skin test. d. A...
C. The error rate with the blood test is greater than the skin test. d. A positive test indicates the person has latent TB infection. e. All of the above 48. What is the role of the medical assistant with IV therapy? a. Schedule appointments for the patient. b. Assist the nurse by communicating issu...
1 answer
Why is it necessary to standardize a indophenol solution? Why is it necessary to titrate blank...
Why is it necessary to standardize a indophenol solution? Why is it necessary to titrate blank samples? Why might the Vitamin C content be underestimated in the case of a heat processed juice sample?...
1 answer
If Piper Manufacturing manufactures one unique set of stack pipes, and the sell price is $121,000,...
If Piper Manufacturing manufactures one unique set of stack pipes, and the sell price is $121,000, the variable costs per unit are $62,000, and the fixed costs are $500,000, what is the break-even point in units? Group of answer choices Approximately 8 units Approximately 2 units Approximately 16 un...
1 answer
San Diego Sheet Metal, Inc. incurs a variable cost of $40 per pound for raw material...
San Diego Sheet Metal, Inc. incurs a variable cost of $40 per pound for raw material to produce a special alloy used in manufacturing aircraft. Required: In the table below, show the unit cost and total cost of raw material at the following production levels: 1 pound, 10 pounds, and 1,000 pound...
1 answer
(1 point) Find the general solution of the differential equation on (0,0): xy" + xy +...
(1 point) Find the general solution of the differential equation on (0,0): xy" + xy + (576x2 – 484)y=0 General solution: y=c] ( )+czy ( ) NOTE REGARDING ANSWER ENTRY: To enter a Bessel function of the form J. (b), you should type a in the first blank and bx in the second blank. Subscripts ...
1 answer
Chemistry one Part 2 (0.5 point) ED MacBook Air week#9 Pre-Lecture Questions(Extra Credit) 03/08/19 01 Question...
chemistry one Part 2 (0.5 point) ED MacBook Air week#9 Pre-Lecture Questions(Extra Credit) 03/08/19 01 Question (2 points) a See page 295 Two balloons are filled to the same pressure at the same temperature. One is filled with 1.40 moles of nitrogen; the other is filled with 1.40 moles of nitrog...