Question

Lab Description Write a program that will search through an array to find the smallest number. You must combine variables, ifpublic class RaySmallest public static int go(int[] ray) return 0;public class SmallestRunner public static void main( String args[])

0 1
Add a comment Improve this question Transcribed image text
Answer #1

RaySmallest.java

public class RaySmallest{

public static int go(int[] ray){
// initial min
int min = ray[0];
// loop through ray
for(int i=1;i<ray.length;i++){
// check and update min
if(min > ray[i]){
min = ray[i];
}
}
return min;
}
}

SmallestRunner.java

public class SmallestRunner {

public static void main(String[] args) {

// declare arrays
int[] a = {-99,1,2,3,4,5,6,7,8,9,10,12345};
int[] b = {10,9,8,7,6,5,4,3,2,1,-99};
int[] l = {10,20,30,40,50,-11818,40,30,20,10};
int[] c = {32767};
int[] d = {255,255};
int[] e = {9,10,-88,100,-555,1000};
int[] f = {10,10,10,11,456};
int[] g = {-111,1,2,3,9,11,20,30};
int[] h = {9,8,7,6,5,4,3,2,0,-2,-989};
int[] i = {12,15,18,21,23,1000};
int[] j = {250,19,17,15,13,11,10,9,6,3,2,1,-455};
int[] k = {9,10,-8,10000,-5000,1000};

// call the go function with each array
System.out.println(RaySmallest.go(a));
System.out.println(RaySmallest.go(b));
System.out.println(RaySmallest.go(l));
System.out.println(RaySmallest.go(c));
System.out.println(RaySmallest.go(d));
System.out.println(RaySmallest.go(e));
System.out.println(RaySmallest.go(f));
System.out.println(RaySmallest.go(g));
System.out.println(RaySmallest.go(h));
System.out.println(RaySmallest.go(i));
System.out.println(RaySmallest.go(j));
System.out.println(RaySmallest.go(k));
}
}

/*
sample output

-99
-99
-11818
32767
255
-555
10
-111
-989
12
-455
-5000
*/

Add a comment
Know the answer?
Add Answer to:
Lab Description Write a program that will search through an array to find the smallest number....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lab Description : Write a program that will sum all of a numbers digits. You must...

    Lab Description : Write a program that will sum all of a numbers digits. You must use % for this lab to access the right most digit of the number. You will use /to chop off the right most digit. Sample Data 234 10000 Files Needed: DigitAdder.java JavaLoopLabRunner.java 9005 84645 8547 123456789 55556468 8525455 8514548 1212121212 Sample Output 14 27 24 45 34 35 15 12 import static java.lang.System.* public class DigitAdder public static int go( int num ) return...

  • Lab Description Sort all words by comparing the length of each word. The word with the...

    Lab Description Sort all words by comparing the length of each word. The word with the smallest length would come first. If you have more than one word with the same length, that group would be sorted alphabetically Input: The data file contains a list of words. The first line in the data file is an integer that represents the number of data sets to follow Output: Output the complete list of words in order by length. Sample Data 10...

  • Lab Description: Using graphics, polygons, and arrays, draw the tree shown below. You can change the...

    Lab Description: Using graphics, polygons, and arrays, draw the tree shown below. You can change the tree anyway you like to make it your own. Sample Data Sec below Files Needed:: GraphicaRunner.java Tree.java Sample Output: import java.awt.Graphics; import java.awt.color; import java.awt.Polygon; import java.awt.Font; import java.awt.Canvas; public class Tree extends Canvas public Tree() setBackground (Color.WHITE) public void paint ( Graphics window) window. setColor (Color.RED); window.setFont (new Font("TAHOMA" ,Font.BOLD,12) window.drawstring("Lab14h Tree Lab", 50, 50) tree(window); IONaA , Font.BOL.D,12) public void tree(Graphics window)...

  • Create a method based program to find if a number is prime and then print all...

    Create a method based program to find if a number is prime and then print all the prime numbers from 1 through 500 Method Name: isPrime(int num) and returns a boolean Use for loop to capture all the prime numbers (1 through 500) Create a file to add the list of prime numbers Working Files: public class IsPrimeMethod {    public static void main(String[] args)    {       String input;        // To hold keyboard input       String message;      // Message...

  • Write a program that instantiates an array of integers named scores. Let the size of the...

    Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...

  • Lab Description: Given a provided array, determine how many groups of a specified size exist. For...

    Lab Description: Given a provided array, determine how many groups of a specified size exist. For the array [i,1,1,2,2,2,3,3,3,4,5, 6, 7], there are 7 groups with at least one, 3 groups with at least 2, and 3 groups with at least 3. A group is a series of same values. 1 1 1 is a group of 3, but it also is a group of 1 and 2. To count as a group, all values must be the same. 1...

  • write a program which include a class containing an array of words (strings).The program will search...

    write a program which include a class containing an array of words (strings).The program will search the array for a specific word. if it finds the word:it will return a true value.if the array does not contain the word. it will return a false value. enhancements: make the array off words dynamic, so that the use is prompter to enter the list of words. make the word searcher for dynamic, so that a different word can be searched for each...

  • Create a program with threads that looks through a vary large array (100,000,000 elements) to find...

    Create a program with threads that looks through a vary large array (100,000,000 elements) to find the smallest number in that array. You should track the current lowest value seen in a single, shared value. You should also track the time taken, comparing the amount of time for 1, 2, 4 and more threads. Fairly precise timing can be obtained by using the System.nanoTime() method. For example, it's taking my poor computer over 1 second to fill my array with...

  • Write in JAVA Get Familiar with the Problem Carefully read the program description and look at...

    Write in JAVA Get Familiar with the Problem Carefully read the program description and look at the data file to gain an understanding of what is to be done. Make sure you are clear on what is to be calculated and how. That is, study the file and program description and ponder! Think! The Storm Class Type Now concentrate on the Storm class that we define to hold the summary information for one storm. First, look at the definition of...

  • Java Programming Write a program to find the number of comparison using binarySearch and the sequentialSearch...

    Java Programming Write a program to find the number of comparison using binarySearch and the sequentialSearch algorithms as follows: Suppose list is an array of 2500 elements. 1. Use a random number generator to fill list; 2. Use a sorting algorithm to sort list; 3. Search list for some items as follows: a) Use the binary search algorithm to search list (please work on SearchSortAlgorithms.java and modify the algorithm to count the number of comparisons) b) Use the sequential search...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT