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]
3 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]3 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
When defining a class, it is a best practice to declare ____ as private. constructors mutators nothing should be private accesso
katrin [286]

Answer:

The answer is "variables".

Explanation:

It is necessary to declare a variable privately when declaring a class because the private variable 'protects' the code while it is in operation. It may not aim to protect it at this stage from changing the codes themselves for other developers. Its purpose of the so-called "data hiding" is to hold the internal data from many other classes using the class protected.

6 0
3 years ago
Can you help me in my work
Ilia_Sergeevich [38]

Answer:

Step 1: harvest. First, you need to select the leaves for harvest. ...

Step 2: steaming. The next step is to heat the leaves by steaming them. ...

Step 3: shaping. ...

Step 4: oxidation. ...

Step 5: drying. ...

Step 6: enjoy your cup of home grown tea. ...

Step 7: storing leftover tea leaves.

5 0
2 years ago
After you save a table, the new table name appears ____.
kobusy [5.1K]
Table1/2.....hope it helps
5 0
3 years ago
Read 2 more answers
Maria found a cupcake recipe on a cooking blog. However, she would like to read comments and suggestions before she begins bakin
Mnenie [13.5K]
Maria should use the Cooking blog that has known and verified information and step by step instructions Comments can lead to disaster and/or incorrect recipe use
8 0
4 years ago
Read 2 more answers
The master production schedule for Product A shows a need for 30 units, and Product B shows a need of 25 units. To manufacture a
alexandr1967 [171]

Answer:

the amount of C required is 190 units of C

Explanation:

the amount of C to cover the necessity of product A is

Ca = A units required * number of C units to manufacture a unit of A

Ca = 30 unit of A * 3 units of C/ unit of A =90 units of C

to produce B the same applies

Cb = B units required * number of C units to manufacture a unit of B

Cb = 25 unit of B * 4 units of C/ unit of B =100 units of C

therefore to cover the necessities of A and also B we will need:

total units of C required = units of C to produce A + units of C to produce B

C = Ca + Cb = 90 units of C + 100 units of C = 190 units of C

C= 190 units of C

3 0
3 years ago
Other questions:
  • Ted is a fashion designer. Where is he most likely to work
    9·1 answer
  • _ is a model of computing in which computer processing, storage, software, and other services are provided as a shared pool of v
    10·1 answer
  • Bryan knows that it takes him fifteen minutes to drive to work, or twenty minutes if every traffic light is red on the way there
    14·2 answers
  • "Career Clusters" describe a group of ________ within the same industry
    14·1 answer
  • 4. Write an appropriate comment for describ-
    11·1 answer
  • List the six external peripheral parts of a computer system
    8·1 answer
  • How is a composite key implemented in a relational database model?
    11·1 answer
  • Astrid's computer screen suddenly says that all files are now locked until money is transferred to a specific account, at which
    11·1 answer
  • 9. Which of the following commands is executed with the shortcut 'Ctrl+Z'?
    11·1 answer
  • Write a C program that reads two hexadecimal values from the keyboard and then stores the two values into two variables of type
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!