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
sp2606 [1]
3 years ago
12

2. Write a program that calls creates an ArrayList of integer and calls the method minToFront described below. Print out the lis

t before and after the method call Method minToFront: takes an ArrayList of integers as a parameter. The method moves the minimum value in the list to the front, otherwise preserving the order of the elements. For example, if a variable called list stores the following values: [4, 7, 9, 2, 7, 7, 5, 3, 5, 1, 7, 8, 6, 7] and you make this call: minToFront(list); it should store the following values after the call: [1, 4, 7, 9, 2, 7, 7, 5, 3, 5, 7, 8, 6, 7]. You may assume that the list stores at least one value. After the call print the list.
Computers and Technology
1 answer:
Novosadov [1.4K]3 years ago
3 0

Answer:

import java.util.ArrayList;

public class MinToFront {

   public static void minToFront(ArrayList < Integer > list){

       int miniIndex = 0;

       for(int j=1; j<list.size(); j++){

          if(list.get(miniIndex) > list.get(j))

               miniIndex = j;

      }

      // moving min to front

       int min = list.get(miniIndex);

       list.remove(miniIndex);

       list.add(0, min);

  }

  public static void main(String[] args) {

       ArrayList<Integer> list = new ArrayList<>();

      list.add(4);   //value store in list

      list.add(7);   //value store in list

      list.add(9);  //value store in list

      list.add(2);  //value store in list

      list.add(7);  //value store in list

      list.add(7);  //value store in list

      list.add(5);  //value store in list

       

      list.add(3);  //value store in list

       

      list.add(5);  //value store in list

       

      list.add(1);  //value store in list

       

      list.add(7);  //value store in list

       

      list.add(8);  //value store in list

       

      list.add(6);  //value store in list

       

      list.add(7);  //value store in list

       

      System.out.println(list);

      minToFront(list);

      System.out.println(list);

  }

}

Output:

[1, 4, 7, 9, 2, 7, 7, 5, 3, 5, 7, 8, 6, 7]

Explanation:

Firstly,we define a method minToFront(), than set an integer variable "miniIndex" to 0, than set a for loop and apply the following condition and inside the loop we apply the if condition, set an integer variable "min" in which we store the value and than we set the following list [4, 7, 9, 2, 7, 7, 5, 3, 5, 1, 7, 8, 6, 7], after that print the list and than print an output.

You might be interested in
. Which game was the most popular free download in Apple®’s app store by January 2014, despite poor reviews and plagiarism accus
Brilliant_brown [7]
Flappy bird for the first question

7 0
3 years ago
Read 2 more answers
A furniture manufacturer wants to find a more environmentally friendly way to make its products. A data analyst helps solve this
Alecsey [184]
The answer has to be true because everything makes sense
4 0
2 years ago
The police department in the city of Computopia has made all streets one-way. The mayor contends that there is still a way to dr
Korvikt [17]

Answer:

a

Explanation:

6 0
2 years ago
Write a function that takes two arguments and returns their sum.
zavuch27 [327]

Answer & Explanation #1

To answer your first query. You can write a function that takes two arguments and returns their sum like this:

#Python program to add two numbers using a function

def add_num(a,b): #function for addition

   sum=a+b

   return sum #return value

num1=25  #variable declaration

num2=55

print("The sum is",add_num(num1,num2)) #call the function

Answer & Explanation #2

As for your error, I believe it is an indent error in your first return statement. All you must do is indent the return statement.

5 0
3 years ago
You'll apply the concepts of Lesson 1 to create pseudocode and a flowchart for a modular program. The body mass index (BMI) is o
Kobotan [32]

In this modular program, the pseudocode and a flowchart for the calculation of person's body mass index (BMI) is given by:

  1. //Ask user for height & weight//
  2. "Enter weight (in pounds):"
  3. "Enter height (in inches"
  4. //Calculate the person's (BMI)//
  5. "BMI = weight * (703 / pow(height, 2));"
  6. //Display the person's (BMI)//

<h3>What is a flowchart?</h3>

A flowchart is also referred to as flow diagram and it can be defined as a graphical representation of an algorithm for a work process or workflow.

<h3>What is a pseudocode?</h3>

A pseudocode can be defined as a description of the steps contained in an algorithm, especially through the use of a plain (natural) language.

In this modular program, the pseudocode and a flowchart for the calculation of person's body mass index (BMI) is given by:

  1. //Ask user for height & weight//
  2. "Enter weight (in pounds):"
  3. "Enter height (in inches"
  4. //Calculate the person's (BMI)//
  5. "BMI = weight * (703 / pow(height, 2));"
  6. //Display the person's (BMI)//

Read more on pseudocode here: brainly.com/question/13208346

#SPJ1

8 0
2 years ago
Other questions:
  • SELECT vendor_name, COUNT(*) AS number_of_invoices, MAX(invoice_total - payment_total - credit_total) AS balance_due FROM vendor
    15·1 answer
  • To create a formula in ___ you would first click in one of the cells. A.word b.excel c.facebook d.powerpoint
    13·1 answer
  • Arpanet was developed by the united states so that there was a communication network that would survive a nuclear war. True or F
    11·1 answer
  • All of the following are incentives proprietary schools use to attract a student except
    7·2 answers
  • A web page ____ can also create a style sheet that takes precedence over the internal style sheets of browsers.
    10·1 answer
  • Encapsulation is the process of “packaging” information prior to transmitting it from one location to another. true or false
    14·1 answer
  • What does ;-; mean during a text?
    8·2 answers
  • Would you rather be rich and unknown or famous and poor
    9·1 answer
  • Write a program that generates 100 random numbers and keeps a count of how many of those random numbers are even and how many of
    15·1 answer
  • . When you ____________________ a word, you can use a single line, a double lines, a dotted line, or even a wavy line!
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!