Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions

Question

=+2 Why did OBI create Centers of Excellence?

Answered: 1 week ago