Question: // Hello world, need help. We are suppose to write a program that displays the largest number and the smalles number , So far i

// Hello world, need help. We are suppose to write a program that displays the largest number and the smalles number, So far i have just been able to print the largest number. Here is my code... The piece of code i have commented towards the bottom is giving me an error.

public static void main(String [] args){

final int LENGTH = 100;

double [] values = new double [LENGTH]; int currentSize = 0; System.out.println("Please enter values. Q to quit: "); Scanner in = new Scanner(System.in); while (in.hasNextDouble() && currentSize < values.length) { values[currentSize] = in.nextDouble(); currentSize ++; }

double largest = values[0]; for (int i = 1; i < currentSize; i ++) { if (values[i] > largest) { largest = values[i]; } } double lowest = values[0]; for ( int i = 1; i < currentSize; i ++) { if (values[i] < lowest ) { lowest = values[i]; } } for (int i = 0; i < currentSize; i ++) { System.out.print(values [i]); if (values[i] == largest) { System.out.print(" <== largest value"); } // for ( int i =0; i < currentSize; i ++) // { // System.out.print(values [i] ); // if ( values[i] == lowest) // { // System.out.print(" <== lowest value"); // // } // } System.out.println(); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!