Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exam Prep: Using Java Programming 1. Write a method called median to determine the median (middle) of three integer values that are passed as parameters

Exam Prep: Using Java Programming

1. Write a method called median to determine the median (middle) of three integer values that are passed as parameters to the method. A solution that involves Arrays.sort will not get any points.

2. Write a method called average that takes two integers as parameters and returns the average of the two integers.

3. Write a method called negativeSum that accepts a Scanner reading input from a file containing a series of integers, and prints a message to the console indicating whether the sum starting from the first number is ever negative (you can assume that the Scanner has already been initialized to read from the file). The negativeSum method should return true if a negative sum is reached and false if not. For example, a file containing : 38 4 19 -27 -15 -3 4 19 38 would result in a message No negative sum displayed in the console and the method would return false. If the file contained : 14 7 -10 9 -18 -10 17 42 98 the method should display sum of -8 after 6 steps and return true.

To help answer this question, I include the solution to a simpler question : display the contents of a file of integers:

public static void fileContents(Scanner input)

{

while (input.hasNextInt())

{

System.out.println(input.nextInt());

}

}

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

More Books

Students also viewed these Databases questions