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
Enumerate the the risk in the preparation and cooking in starch and cereal dishes and other food​
Novay_Z [31]
———————————————————.
6 0
2 years ago
Create a program in Matlab that prints the numbers from 1-100.
Burka [1]

Answer:

numbers = 1:1:100;

for num=numbers

remainder3 = rem(num,3);

remainder5 = rem(num,5);

 

if remainder3==0

disp("Yee")

else

if remainder3 == 0 && remainder5 == 0

disp ("Yee-Haw")

else

if remainder5==0

disp("Haw")

else

disp("Not a multiple of 5 or 4")

end

end

end  

end

Explanation:

  • Initialize the numbers variable from 1 to 100.
  • Loop through the all the numbers and find their remainders.
  • Check if a number is multiple of 5, 3 or both and display the message accordingly.
4 0
3 years ago
How to drive more website traffic?
lidiya [134]

Hello there,

How to drive more website traffic?

Answer: Advertise

8 0
3 years ago
In your own words, describe the advantages and disadvantages of the auto-negotiation protocol used in Ethernet communications.
dexar [7]

Answer:

 Auto-negotiation protocol is the modern technology in the networking. This protocol allow the ethernet equipment for automate different instillation steps. This type of protocol use by interconnecting various electronic devices for negotiating the speed of the link.  

Advantages:

  •  The auto negotiation protocol features used to maximize the throughput of data link layer.
  •  This protocol are basically useful in the local area network (LAN), with multiple capability of connections.
  •  The auto negotiation protocol extremely useful in twisted pair which are based on ethernet.

Disadvantages:

  •   This type of protocol are not fixed data links and not used as backbone of the networks.  
  •  Duplex mismatch occur then, it cause significant loss in the packets.

7 0
3 years ago
A database is used instead of a spreadsheet when
guajiro [1.7K]
            Both spreadsheets and databases, play a part in the daily
    operations of many businesses. While you do not necessarily need to choose between spreadsheets and databases, they are often suited to different types of tasks. Understanding the key differences between spreadsheets and databases is vital if you want to make the best use of either or both of them.
     Spreadsheets and databases share some characteristics, but they involve different technologies.
               Databases generally involve a higher level of technical processing.
-Rosie
4 0
3 years ago
Other questions:
  • Which is NOT a way the network operating sys-
    6·1 answer
  • true /falseCompression of entries in the term-document matrix can be used to reduce run-time storage and execution-time requirem
    10·1 answer
  • Show the subnet address, subnet mask in slash notation, broadcast address, number of addresses, first valid host address, and th
    13·1 answer
  • How is abstraction used in a GPS system
    9·2 answers
  • If a memory reference takes 100 nanoseconds, how long does a paged memory reference take?
    6·1 answer
  • You are the administrator of the Sybex website. You are working when suddenly web server and network utilization spikes to 100 p
    15·1 answer
  • Create a Divisible application that displays a random integer between 1 and 100 and displays appropriate messages stating whethe
    5·1 answer
  • ¡Hola! He visto en muchos comentarios de Twitter "svd" cuando alguien dice "dale fav a este Tweet y siganse entre ustedes" y en
    8·1 answer
  • A student wants an algorithm to find the hardest spelling word in a list of vocabulary. They define hardest by the longest word.
    9·1 answer
  • a central issue in the microsoft antitrust lawsuit involved microsoft's integration of its internet browser into its windows ope
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!