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
Shut down and unplug the computer. Remove the CPU case lid. Locate the various fans, and then use
nlexa [21]

Answer:

Cleaning the fan

Explanation:

Just did it on Ed

Would you mind giving me brainliest?

6 0
3 years ago
Can someone help me with this
Alex787 [66]
I’m not sure but I think it belongings.
5 0
2 years ago
In a relational database model, a(n) _____ operation pares down a table by eliminating columns according to certain criteria. in
nikklg [1K]

I guess the correct answer is Project

If thе usеr is intеrеstеd in sеlеcting thе valuеs οf a fеw attributеs, rathеr than sеlеctiοn all attributеs οf thе Tablе (Rеlatiοn), thеn οnе shοuld gο fοr Prοjеct Οpеratiοn.

8 0
3 years ago
Please help me with these short questions &gt;..
Thepotemich [5.8K]

Answer:

bmjcmbbobnkpkkjkbk

Explanation:

vuvkopbbkvkhovjlplbkp

6 0
2 years ago
Suggest me a website or any channel for learning coding.
gulaghasi [49]

Answer: Codeacademy. One of the most popular free places to learn coding is Codeacademy.

Explanation:

6 0
3 years ago
Other questions:
  • . Gathering information with your eyes is called __________.
    6·1 answer
  • How long will twenty percent of battery life last me?
    14·2 answers
  • Among the following, which is the best protection against ransomware?
    8·1 answer
  • What are two examples of management information systems?
    12·1 answer
  • hello my friend is doing a give away at 100 followers would you follow him for a chance to win 2000 vbucks his name is ZoVa_Velo
    15·2 answers
  • In this lab you will learn about the concept of Normal Forms for refining your database design. You will then apply the normaliz
    15·1 answer
  • Imagine that you wanted to write a program that asks the user to enter in 5 grade values. The user may or may not enter valid gr
    10·1 answer
  • In what real-life situations might you want to use the modulus operation in a program?
    15·1 answer
  • Which statement is true about the energy of electromagnetic radiation?
    15·1 answer
  • If I use the command right(90), which way will Tracy turn?<br> If correct I mark brainlist
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!