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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started