Java problem
In this problem, the first input is a positive integer called n that will represent the number of lines to process. The lines to be processed have one or more integers separated by whitespaces. For each of these lines, you must output:
The minimum value of the integers
The maximum value of the integers
The sum of the integers
It is worth to mention that the number of integers of each line is not known a priori and can varry from line to line. Write a program that solve this requirement.
Input Format
The first line contains n, the number of lines to be processed. The remaining n lines are the lines to be processed.
Constraints
n must be a positive integer.
The lines to be processed must have at least one integer.
Output Format
For each line to be processed, the output must be formed by 3
space-separated integers: min max sum
min: the minimum value of the integers of the
line.
max: the maximum value of the integers of the
line.
sum: the sum of the integers of the line.
Sample Input 0
4 -9 17 77 -18 55 0 42 11 7 90 -2 -15 30 -8 0 2 8 12 22 -1 5
Sample Output 0
-18 77 67 -15 90 218 -8 2 -6 -1 22 46
/*The whole answer is well commented so please create a class SumMinMax.java and copy whole answer and execute
*
*Here I will use BufferedReader to read input from console because it is fastest and
*best read lines from console but It reads lines in string format you need to process it
*
*So You can use Integer.parseInt(str) method to convert a string to integer
*str.split() method to split string
*
* So after reading input as string i will convert the string to integer of array then
* We can find min max easily in array of integer
*
* How to find min?
* Declare a variable min;
* assign arr[0] means first element of array to it min=arr[0]
* now iterate over array from index 1 to n-1 and check if(arr[i]<min) then
* modify the value of min as min=arr[i]
*
* ex- arr=[5,2,1]
* min=arr[0]=5
* if(arr[1]<min) => 2<5 => min=2
* if(arr[2]<min) => 2<1 => min=1
* So same procedure for max
*
*
* Sample Input:
4
-9 17 77 -18
55 0 42 11 7 90 -2 -15 30
-8 0 2
8 12 22 -1 5
*Sample Output:
-18 77 67
-15 90 218
-8 2 -6
-1 22 46
*If you are copy pasting input then press Enter to see last output
*/
import java.io.*;
import java.util.*;
public class SumMinMax {
public static void main(String[] args) throws IOException {
//Instantiating BufferedReader
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
//Now Reading n as it is single integer we can directly convert to integer
//ReadLine method reads a complete line from console
int n=Integer.parseInt(br.readLine());
//Below code of block will read n lines and find min -max -sum
for(int t=1;t<=n;t++)
{
//Below line will read a line and split it and will create array of Strings
String[] strs=br.readLine().split(" ");
//Finding number of elements in line
int len=strs.length;
//Creating integer array
int[] numbers=new int[len];
//Now Converting array of strings to array of integers
for(int i=0;i<len;i++)
{
numbers[i]=Integer.parseInt(strs[i]);
}
//Declaring min, max, sum variable
int min=numbers[0];
int max=numbers[0];
int sum=numbers[0];
for(int i=1;i<len;i++)
{
//Checking for min
if(numbers[i]<min)
min=numbers[i];
//Checking for max
if(numbers[i]>max)
max=numbers[i];
//Adding to sum
sum =sum +numbers[i];
}
//Printing out
System.out.println(min+" "+max+" "+sum);
}
}
}
Java problem In this problem, the first input is a positive integer called n that will...
Java
Input Format For Custom Testing The first line contains an integer, n, that denotes the number of elements in s. Each line i of the n subsequent lines (where 0 si<n) contains a string that describes s[i]. Sample Case 0 Sample Input For Custom Testing 4 code aaagmnrs anagrams doce Sample Output aaagmnrs code Explanation aaagmnrs and anagrams are anagrams, code and doce are anagrams. After sorting aaagmnrs comes first. Sample Case 1 Sample Input For Custom Testing 4...
Python Script format please!
1. Write a script that takes in three integer numbers from the
user, calculates, and displays the sum, average, product, smallest,
and largest of the numbers input. Important things to note: a. You
cannot use the min() or max() functions, you must provide the logic
yourself b. The calculated average must be displayed as an integer
value (ex. If the sum of the three values is 7, the average
displayed should be 2, not 2.3333). Example:...
Homework 2 Description This homework will test the use of arrays and control structures. In summary, you will read 10 integers from standard input, store them into an array and then produce some statistics. Details You need to compute Array Statistics. Create a class called Hwk2 that implements a main to solve your homework. At the beginning display a line with the following text: Type 10 integer values: Then, read 10 integers from standard input, one by one and store...
Preferably in python but java is good too
Task 1: Minimum Spanning Trees For this warm-up task you are to implement any efficient minimum spanning tree algorithm that takes a sequence of edge-weighted graphs and outputs the minimum cost weight of a spanning tree of each Input Format For this assignment we use adjacency matrices with positive integer weights. Here a zero entry at row i and column J indicates that no edge i] exists in the graph. The first...
Please write code in java You’re given a chess board with dimension n x n. There’s a king at the bottom right square of the board marked with s. The king needs to reach the top left square marked with e. The rest of the squares are labeled either with an integer p (marking a point) or with x marking an obstacle. Note that the king can move up, left and up-left (diagonal) only. Find the maximum points the king...
Problem Description proving program correctness Consider the following program specification: Input: An integer n > 0 and an array A[0..(n - 1)] of n integers. Output: The smallest index s such that A[s] is the largest value in A[0..(n - 1)]. For example, if n = 9 and A = [ 4, 8, 1, 3, 8, 5, 4, 7, 2 ] (so A[0] = 4, A[1] = 8, etc.), then the program would return 1, since the largest value in...
Please submit only Python source code. 1. Arithmetic trees 50 marks You are given an input file with multiple pairs of input lines. The first line of each pair is a tree given as a predecessor array. The second line is the value at the corresponding node. Values at leaf nodes (nodes with no children) are integers. At non-leaf nodes, the two possible values are + or *. The tree represents an arithmetic expression where the value at a non-leaf...
(Java Programmin): Sum() and max() in ArrayList a. Write a method that returns the maximum value in an ArrayList of integers. The method returns null if the list is null or the list size is 0. public static Integer max(ArrayList<Integer> list) b. Write a method that returns the sum of all numbers in an ArrayList: public static Integer sum(ArrayList<Integer> list) c. Write a test program that prompts the user to enter a sequence of numbers ending with 0, and invokes...
Please use Java for this question.
Input Format Format for Custom Testing Input from stdin will be processed as follows and passed to the function In the first line, there is a single integer n. In the second line, there is a single integer m. In the ph of the next n lines there are m space-separated integers denoting the throw of the initial grid. In the next line, there is a single integer k. In the next line,...
Binary Search Tree (C++) Input Two lines. The first line is a integer n; the second line are n numbers. Output Two lines. First line is the in-order traversal; second line is the post-order traversal. Sample Input 8 23 45 12 6 7 89 13 47 Sample Output 6 7 12 13 23 45 47 89 7 6 13 12 47 89 45 23 Hint If meet equal number, go through the right tree.