Main topics: Arrays Effective size Searching arrays Sorting arrays Exercise This lab is designed to give you practice wo

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Main topics: Arrays Effective size Searching arrays Sorting arrays Exercise This lab is designed to give you practice wo

Post by answerhappygod »

Main Topics Arrays Effective Size Searching Arrays Sorting Arrays Exercise This Lab Is Designed To Give You Practice Wo 1
Main Topics Arrays Effective Size Searching Arrays Sorting Arrays Exercise This Lab Is Designed To Give You Practice Wo 1 (38.35 KiB) Viewed 29 times
Main Topics Arrays Effective Size Searching Arrays Sorting Arrays Exercise This Lab Is Designed To Give You Practice Wo 2
Main Topics Arrays Effective Size Searching Arrays Sorting Arrays Exercise This Lab Is Designed To Give You Practice Wo 2 (29.54 KiB) Viewed 29 times
Main topics: Arrays Effective size Searching arrays Sorting arrays Exercise This lab is designed to give you practice working with arrays. Specifically you will be searching and sorting an existing array of values. Getting Started To start this exercise, you should 1. Open eclipse and start a new Java project named Lab11 2. Add a Class (named Lab11) to this project. 3. Cut the program from this document and paste (replacing everything) in the Eclipse editor window. Lab11.Java import java.util.Scanner; public class Lab11 { public static void main(String[] args) { Scanner stdIn new Scanner (System.in); final int Size = 10; double scores new double [Size]; // set all the scores to a random number [0-99] for (int = 0; s < Size; ++s) scores [s] = (int) (Math.random() 100); // print the scores - original order System.out.println("Scores Original"); System.out.println("-- print Array (scores, Size); System.out.println("\n"); // sort the scores System.out.println("Sorting.\n"); // print the scores sorted order System.out.println("Scores - Sorted"); System.out.println("------ ---------); print Array (scores, Size);
System.out.println("\n"); atdIn.close(); } public static void printArray (double [] arr, int eSize) ( for (int i = 0; i < eSize; ++i) System.out.println(arr); } public static int findMinLoc (double arr, int startInd, int endInd) { int minLoc startInd; for (int i startInd+ 1; i < endInd; ++i) { if (arr<arr [minLoc]) minLoc i; } return minloc; } public static void swapInArray (double [] arr, int indi, int ind2) ( double tmp arr [indi]; arr [indi] arr[ind2); arr [ind2] = tmp; } public static void sortArray (double [] arr, int eSize) ( for (int i = 0; i < eSize; ++i) { int ind findMinLoc (arr, i, eSize-1); swapInArray (arr, i, ind); } Problem Description . For this exercise you will be using the Lab11.java file that you copied using the command above. • In this file, we have provided you with a fully functional program that: - Declares an array of doubles. -Sets each element in the array to a random number. - Prints the array elements to the screen.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply