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