1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mestny [16]
2 years ago
13

Complete the getOdds method so it returns a new ArrayList of Integers containing all odd Integers from the parameter ArrayList v

als in the order they originally appeared. The contents of vals should not change. For example if an ArrayList containing the Integers 2,5,8,6,7,3, 12 in that order is passed as a parameter to getOdds, it should return an ArrayList containing the Integers 5, 7,3 in that order. Write your getOdds method in the U7_L2_Activity Three class. Use the runner class to test your method but do not add a main method to your U7_L2_Activity Three.java file or your code will not be scored correctly.
Computers and Technology
1 answer:
kow [346]2 years ago
3 0

Answer:

Following are the code to this question:

import java.util.*;//import package for user-input

public class U7_L2_Activity Three//defining  class U7_L2_Activity Three

{

  public static ArrayList<Integer> getOdds(ArrayList<Integer> val)//defining a static method getOdds as an ArrayList

  {

      ArrayList<Integer> odd = new ArrayList<Integer>();//creating ArrayList Object  

      int i; //defining integer variable  

      for(i=0;i<val.size();i++)//defining for loop for calculating odd values

      {

          if(val.get(i)%2!=0)//defining if block to check odd numbers

          {

              odd.add(vals.get(i));//add values in odd ArrayList  

          }

      }

      return odd;//return ArrayList odd

  }

  public static void main(String[] asr)//defining main method

  {

      int l,i;//defining integer variable

      Scanner sob = new Scanner(System.in);//creating Scanner calss Object

      ArrayList<Integer> num = new ArrayList<Integer>();//creating ArrayList object  

      System.out.println("Enter length of the ArrayList: ");//print message

       l = scan.nextInt();//input length value

      System.out.println("Enter ArrayList values: "); //print message  

      for(i = 0; i < l; i++)//use for to input value  

      {

          num.add(sob.nextInt());//input value

      }

      System.out.println("Odds list: " + getOdds(num));//calling method getOdds

      System.out.println("Original list: " + num);//print array value

  }

}

Output:

Enter ArrayList length:

7

Enter values:

2

5

8

6

7

3

12

Odds list: [5, 7, 3]

Original list: [2, 5, 8, 6, 7, 3, 12]

Explanation:

In the above-program inside the class, a static method "getOdds "is declared, that accepts an array list in its parameters, and defined an array list "odd", in this a for loop is defined, that check the odd numbers in the array and add the value in the odd Arraylist, and returns its values.

Inside the main method is defined that creates scanner class object for input array value and pass the value into the method "getodds" and print its return values.

You might be interested in
What are the ethical implications of online social media after someone has died?
ZanzabumX [31]
<span>Think about the things people might have wanted private, but after death they have no control.</span>
8 0
3 years ago
What is the value of: 1 + int(3.5) / 2?<br> Select one:<br> a. 2<br> b. 2.25<br> C. 2.5<br> d. 3
Drupady [299]

Answer:

C (2.5)

Explanation:

int(3.5) = 3

So, using order of operations, (3/2)+1=2.5

8 0
3 years ago
Explain why database management systems are used in hospitals? Discuss
Sergeeva-Olga [200]

The reason why database management systems are used in hospitals is because the use of Healthcare databases aids in terms of diagnosis and treatment, handle documentation and billing, and others.

<h3>What is a database management system in healthcare?</h3>

A database management system (DBMS) is known to be a type of software that has been developed to help people to form and keep databases.

It is one that helps to lower the risk of errors associated with medical operations and management. It reduces  paperwork and staff and also improves  performance.

Learn more about database management from

brainly.com/question/24027204

8 0
2 years ago
Don't click on this I am testing
Andrew [12]

Don't click on this I am testing... I want the points so.

3 0
2 years ago
Read 2 more answers
A(n) _____ converts the programming instructions written by programmers into a language that the computer understands and proces
qaws [65]

Answer: Translator

Explanation:

each instruction written by programmer in another language must be converted (translated) to machine language in order to process, because computer understand only machine language( 0 and 1). that is translator.

8 0
3 years ago
Other questions:
  • (I'LL GIVE BRAINLIST)
    10·2 answers
  • Upon looking out at the
    8·2 answers
  • Explain the use of keyboard shortcuts and key combinations. You are at the tenth page of a 20-page document. You need to make ch
    14·1 answer
  • Consider the following code segment. int[] seq = {3, 1, 8, 4, 2, 5}; for (int k = 1; k &lt; seq.length; k++) { if (seq[k] &gt;=
    5·1 answer
  • Convert each of the following base 10 &amp; base 2 numbers in signed magnitude, one’s complement and two’s complement. Each of t
    8·1 answer
  • What type of machine is a hand drill?<br><br> A. Simple machine <br> B. Compound machine
    8·2 answers
  • Write a brief, two-page paper describing how your lifestyle and values impact your use of the Web for e-commerce. How is your on
    15·1 answer
  • Among your selection in different online interfaces, which are your top three favorites?​
    7·2 answers
  • Fill in the blanks with the correct words.
    7·1 answer
  • A(n) ____________ calculator is a device that assists in the process of numeric calculations but requires the human operator to
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!