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
I have a bag of trail mix.half of the bag contains peanuts.1/4of the bag is chocolates candies, and 1/4of the bag is dried fruit
nika2105 [10]
A.) 1/2 Half the bags are peanuts so you have 1/2 a chance of selecting s peanut.
6 0
3 years ago
Read 2 more answers
What are wizard ranks in brainly​
Hunter-Best [27]

Answer:

Brainly gives special ranks to users who give outstanding performance in a specific subject. These ranks are known as Wizard rank. Specifically for only one person in each subjects: Maths, Chemistry, Physics, Biology, and English.

Explanation:

4 0
3 years ago
Read 2 more answers
Can i get some help please .
Alex787 [66]

Answer:

Interest

So, lets say that you took a loan from the bank of 20,000. But, when you are supposed to pay it back, you need to pay 25,000. This is because of interest. When the bank gives you the money, they cannot give it to you just like that. There is no profit coming from it. So, there is the thing called interest which basically says that since you took money from the bank, you need to pay a little more because you borrowed money from them.

4 0
2 years ago
Read 2 more answers
You need to upgrade memory in a system but you don't have the motherboard documentation available. you open the case and notice
Harlamova29_29 [7]
<span>The three yellow slots probably indicate triple channeling, which means the board uses DDR3 DIMMs. To know for sure, remove a DIMM and look for the position of the notch on the DIMM.</span>
6 0
3 years ago
Computer security experts devote their time and energy to the protection of sensitive data and the prevention of an outside atta
Alik [6]

Answer:

Information security policy are used for the prevention of intruders hacking a network when an organization start getting IT related attacks.

Explanation:

Information security policy are used for the prevention of intruders hacking a network when an organization start getting IT related attacks.

An information security policy are set of rules/policies designed to guide employees for the protection of the security of company information and IT systems. The reasons for these policies are:

  1. It defines what is required from organization’s employees for the security of the IT systems
  2. Information security policies provide a means to secure the organization against external and internal threats
  3. Information security policies are a mechanism to for ensuring an organization’s legal and ethical responsibilities
  4. Information security policies are created to hold each employee responsible with regard to information security
4 0
3 years ago
Other questions:
  • In a student​ database, a row that describes the top​ student, including his or her​ lastname, firstname, and​ studentnumber, is
    9·1 answer
  • Which data type uses more memory an integer or an unsigned integer?
    6·1 answer
  • What is a good voltage measurement on a brand new, 6 volt golf cart deep cycle battery after the first charging?
    10·1 answer
  • When a range of IP addresses is set aside for client devices, and one of these IPs is issued to these devices when they request
    14·1 answer
  • What is a Photojournalist
    5·1 answer
  • what is a massive online storage that allows for Access by any internet-connected device running web browser. use for Less priva
    6·1 answer
  • A man-made world event that would affect the labor market would be a(n) _____.
    13·1 answer
  • I will upvote....
    10·1 answer
  • Before posting a picture online, make sure to
    7·1 answer
  • The computer scientists Richard Conway and David Gries once wrote: The absence of error messages during translation of a compute
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!