Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Find and print the largest and smallest numbers. 2. Find the largest number in the half of all numbers stored. Using this java code

1. Find and print the largest and smallest numbers.

2. Find the largest number in the half of all numbers stored.

Using this java code below

import java.util.ArrayList; import java.util.Scanner; /** This program reads a sequence of values and prints them, marking the largest value. */ public class LargestInArrayList { public static void main(String[] args) { ArrayList values = new ArrayList(); // Read inputs System.out.println("Please enter values, Q to quit:"); Scanner in = new Scanner(System.in); while (in.hasNextDouble()) { values.add(in.nextDouble()); } // Find the largest value double largest = values.get(0); for (int i = 1; i < values.size(); i++) { if (values.get(i) > largest) { largest = values.get(i); } } // Print all values, marking the largest for (double element : values) { System.out.print(element); if (element == largest) { System.out.print(" <== largest 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

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

What gets displayed by the pseudocode below? a b){ b

Answered: 1 week ago

Question

When is it appropriate to use a root cause analysis

Answered: 1 week ago