Question

In: Computer Science

1. Write a program that computes the smallest and largest of a set of values that...

1. Write a program that computes the smallest and largest of a set of values that are stored in an array. Ask the user for the set size (and hence the array size). Populate the array with user input.

Solutions

Expert Solution

import java.util.Scanner;

public class Main
{
   public static void main(String[] args) {
   Scanner sc=new Scanner(System.in);
   System.out.print("Enter the size of array:");
   int n=sc.nextInt();
   int a[]=new int[n];
  
   for(int i=0;i<n;i++){
System.out.print("Enter the element"+(i+1)+":");
a[i]=sc.nextInt();
   }

int minimum=a[0];int maximum=a[0];
for(int i=0;i<n;i++){
if(a[i]<=minimum)
minimum=a[i];
if(a[i]>=maximum)
maximum=a[i];
}
System.out.println("smallest number in array:"+minimum);
System.out.println("largest number in array:"+maximum);


   }
}



Related Solutions

1. Write a program that computes the smallest and largest of a set of values that...
1. Write a program that computes the smallest and largest of a set of values that are stored in an array. Ask the user for the set size (and hence the array size). Populate the array with user input. (Java language)
Write a Java program to get the difference between the largest and smallest values in a...
Write a Java program to get the difference between the largest and smallest values in a user inputed array of integers. The length of the array must be 1 and above
Summary In this lab, you complete a prewritten Python program that computes the largest and smallest...
Summary In this lab, you complete a prewritten Python program that computes the largest and smallest of three integer values. The three values are -50, 53, 78. Instructions Two variables named largestand smallest are assigned for you. Use these variables to store the largest and smallest of the three integer values. You must decide what other variables you will need and initialize them if appropriate. Write the rest of the program using assignment statements, if statements, or elifstatements as appropriate....
Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values.
 in Coral Simulator  Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. If the input is 7 15 3, the output is: largest: 15 smallest: 3 Your program should define and call two functions: Function LargestNumber(integer num1, integer num2, integer num3) returns integer largestNum Function SmallestNumber(integer num1, integer num2, integer num3) returns integer smallestNum The function LargestNumber should return the largest number of the...
1. For each set of atoms/ions, write them in increasing order of size (smallest to largest)...
1. For each set of atoms/ions, write them in increasing order of size (smallest to largest) a. Mg2+, Se2- , S2- , K+ , Ca2+ b. Ga, Si, Rb, N, In c. A2+, B+ , C, D- , E2- if these elements are isoelectronic (same number of electrons) d. Put the following elements, S, Ba, Bi, Cl, Te, Ar in order of increasing ionization energy, and increasing electron affinity. 2. The following questions involve the following atoms: Ge, As, K,...
• Write a C++ program to find the largest umber, smallest number and sum of all...
• Write a C++ program to find the largest umber, smallest number and sum of all the element of a given array of 20 integers • Note − Declare array to 20 numbers − Input values for 20 array elements − Find largest number − Find smallest number − Find sum of all numbers • Display the results
Write a Python program that computes certain values such as sum, product, max, min and average...
Write a Python program that computes certain values such as sum, product, max, min and average of any 5 given numbers along with the following requirements. Define a function that takes 5 numbers, calculates and returns the sum of the numbers. Define a function that takes 5 numbers, calculates and returns the product of the numbers. Define a function that takes 5 numbers, calculates and returns the average of the numbers. Must use the function you defined earlier to find...
Let A and B be two events. Find the largest and smallest possible values P(A U...
Let A and B be two events. Find the largest and smallest possible values P(A U B) can take in terms of P(A) and P(B) and give examples in which these values can be attained.
Write an algorithm that finds both the smallest and largest numbers in a list of n...
Write an algorithm that finds both the smallest and largest numbers in a list of n numbers. Try to find a method that does at most 1.5n comparisons of array items.(but please code in java).
Using C Language Write a program segment that computes 1 + 2 + 3 + ......
Using C Language Write a program segment that computes 1 + 2 + 3 + ... + ( n - 1) + n , where n is a data value. Follow the loop body with an if statement that compares this value to (n * (n + 1)) / 2 and displays a message that indicates whether the values are the same or different. Please give me code to just copy and paste
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT