Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

JAVA Choose one of the exercises you did in this session and re-write your code using the tips and standards given to you in the

JAVA

Choose one of the exercises you did in this session and re-write your code using the tips and standards given to you in the handout on refactoring.

import java.util.ArrayList; import java.util.Scanner; public class SortArray { public static void sort(ArrayList list) { Integer temp; for(int i = 0; i < list.size(); ++i) { for(int j = 0; j < list.size()-1; ++j) { if(list.get(j).compareTo(list.get(j+1)) > 0) { temp = list.get(j); list.set(j, list.get(j+1)); list.set(j+1, temp); } } } } public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList list = new ArrayList<>(); System.out.println("Enter 5 numbers: "); for(int i = 0; i < 5; ++i) { list.add(in.nextInt()); } System.out.println("Normal list: " + list.toString()); sort(list); System.out.println("Sorted list: " + list.toString()); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Draw a picture consisting parts of monocot leaf

Answered: 1 week ago