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
emmasim [6.3K]
3 years ago
10

Write the following generic method that sorts an ArrayList of Comparable items. The sort method must use the compareTo method.

Computers and Technology
1 answer:
Inessa05 [86]3 years ago
6 0

Answer:

Explanation:

The following code is written in Java, it prompts the user to enter 10 integers and saves them to an ArrayList. Then it prompts for 5 strings and saves them to another ArrayList. Then, it calls the sort method and adds the lists as parameters. Finally, it prints out both lists completely sorted in ascending order.

import java.util.ArrayList;

import java.util.Scanner;

class Division{

   public static double division(double a, double b) throws Exception {

       if(b == 0)

           //throw new Exception("Invalid number.");

           return (a / b);

       return a / b;

   }

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

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

       for (int x = 0; x < 10; x++) {

           System.out.println("Please Enter a Number: ");

           int number = in.nextInt();

           mylist2.add(number);

       }

       ArrayList<String> mylist = new ArrayList<>();

       for (int x = 0; x < 5; x++) {

           System.out.println("Please Enter a Word: ");

           String word = in.nextLine();

           mylist.add(word);

       }

       sort(mylist);

       sort(mylist2);

       for (String x: mylist) {

           System.out.print(x + ", ");

       }

       System.out.println("");

       for (int x: mylist2) {

           System.out.print(x + ", ");

       }

   }

   public static <E extends Comparable<E>> ArrayList<E> sort(ArrayList<E> list) {

       E temp;

       if (list.size()>1) // check if the number of orders is larger than 1

       {

           for (int x=0; x<list.size(); x++) // bubble sort outer loop

           {

               for (int i=0; i < list.size() - x - 1; i++) {

                   if (list.get(i).compareTo(list.get(i+1)) > 0)

                   {

                       temp = list.get(i);

                       list.set(i,list.get(i+1) );

                       list.set(i+1, temp);

                   }

               }

           }

       }

       return list;

}}

You might be interested in
Privacy, anonymity, and freedom of expression are all interrelated.
Andre45 [30]

Answer:

Criminals (terrorists).

Explanation:

6 0
3 years ago
.In Python, comments begin with the comment marker and continue ______.
earnstyle [38]

Answer:

b. to the end of the line

Explanation:

Great question, it is always good to ask away and get rid of any doubts that you may be having.

Python is a unique language compared to other languages such as Java and C++. In Python comments are started with the comment marker which is the hashtag (#) symbol and continues <u>to the end of the current line</u>. Once the line ends the next line is <u>NOT</u> automatically considered a comment unless another hashtag is placed.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

4 0
2 years ago
If you design your pages using a font that your user does not have installed, the browser defaults to ____ on a macintosh.
sveticcg [70]
The browser should default to Calibri (body)
3 0
3 years ago
Since the password includes all four types of characters (complex password) and is 8 characters long, what is the real reason th
Liono4ka [1.6K]
It makes the possibility of an unwanted user to break into your account much smaller.
8 0
3 years ago
In what kind of attack can attackers make use of millions of computers under their control in an attack against a single server
rjkz [21]

Answer:

Distributed DOS attacks.

Explanation:

Computers in a network or the network itself is are prone to cyber attacks. A cyber attack is a concept of taking advantage of computer network vulnerabilities, to retrieve information from the target source. An example of these types of security attacks is the denial of service (or DOS) attacks.

The DOS  or the distributed DOS attack prevents users form accessing or requesting a service that they are legitimately allowed, by flooding the target system with superfluous resource request from millions of computers, controlled by the attacker.

8 0
3 years ago
Other questions:
  • A pacing calendar is provided to students so they can:
    8·2 answers
  • What were the goals of the “paperless society” ideal?
    14·2 answers
  • A computer’s BIOS is defined as the
    12·2 answers
  • Write a short program that allows the user to input a positive integer and then
    5·1 answer
  • Which of the following “invisible” marks represents an inserted tab?
    11·2 answers
  • Here is the problem specification: An Internet service provider has three different subscription packages for its customers: Pac
    5·1 answer
  • In java I need help on this specific code for this lab.
    5·1 answer
  • A _____ is an Access database object that allows you to arrange the fields of a record in any layout so you can enter, edit, and
    6·1 answer
  • HELP 100 points
    9·1 answer
  • Numerous engineering and scientific applications require finding solutions to a set of equations. Ex: 8x + 7y = 38 and 3x - 5y =
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!