1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vovikov84 [41]
3 years ago
9

Write a main program that prompts users for 5 integers. Use two separate functions to return (NOT print) the highest and lowest

value of the 5 integers. From main, display all five numbers entered and the results.
Computers and Technology
1 answer:
Soloha48 [4]3 years ago
6 0

Answer:

import java.util.Arrays;

import java.util.Scanner;

public class LatinHire {

   public static void main(String[] args) {

       Scanner in = new Scanner (System.in);

       System.out.println("Enter Five integers");

       int num1 = in.nextInt();

       int num2 = in.nextInt();

       int num3 = in.nextInt();

       int num4 = in.nextInt();

       int num5 = in.nextInt();

       int [] intArray = {num1,num2,num3,num4,num5};

       System.out.println(Arrays.toString(intArray));

       System.out.println("The Maximum is "+returnMax(intArray));

       System.out.println("The Minimum is "+returnMin(intArray));

   }

   public static int returnMax(int []array){

       int max = array[0];

       for(int i=0; i<array.length; i++){

           if(max<array[i]){

               max= array[i];

           }

       }

       return max;

   }

   public static int returnMin(int []array){

       int min = array[0];

       for(int i=0; i<array.length; i++){

           if(min>array[i]){

               min= array[i];

           }

       }

       return min;

   }

}

Explanation:

  1. This is implemented in Java Programming Language
  2. Two Methods are created returnMax(Returns the Maximum Value of the five numbers) and returnMin(Returns the minimum of the five numbers)
  3. In the Main method, the user is prompted to enter five numbers
  4. The five numbers are saved into an array of integers
  5. The returnMax and returnMin methods are called and passed the array as parameter.
  6. The entire array of numbers inputted by the user as well the Max and Min are printed

You might be interested in
Write a method that computes the sum of the digits in an integer. Use the following method header: public static int sumDigits(l
kifflom [539]

Answer:

The java program for the given scenario is shown below.

import java.util.*;

import java.lang.*;

public class Test

{

   //variables to hold the number, digits and sum of the digits

   //variable to hold number is assigned any random value

   static long num=123;

   static int sum=0;

   static int digit;

   static int s;

   //method to add digits of a number

   public static int sumDigits(long n)

   { do

       {

           digit=(int) (n%10);

           sum=sum+digit;

           n=n/10;

       }while(n>0);

       return sum;

   }

public static void main(String[] args) {

    s = sumDigits(num);

 System.out.println("The sum of the digits of "+num+ " is "+s);  }

}

OUTPUT

The sum of the digits of 123 is 6

Explanation:

1. The variables to hold the number is declared as long and initialized.

2. The variables to store the digits of the number and the sum of the digits are declared as integer. The variable, sum, is initialized to 0.

3. The method, sumDigits(), is defined which takes a long parameter and returns an integer value. The method takes the number as a parameter and returns the sum of its digits.

4. Inside method, sumDigits(), inside the do-while loop, the sum of the digits of the parameter is computed.

5. Inside main(), the method, sumDigits(), is called. The integer value returned by this method is stored in another integer variable, s.

6. The sum of the digits is then displayed to the console.

7. All the variables are declared outside main() and at the class level and hence declared static. The method, sumDigits(), is also declared static since it is to be called inside main().

8. In java, the whole code is written inside a class since java is a purely object-oriented language.

9. In this program, object of the class is not created since only a single class is involved having main() method.

10. The program can be tested for any value of the variable, num.

11. The file is saved as Test.java, where Test is the name of the class having main() method.

7 0
2 years ago
You've applied a filter. What's the best way to see the original data?
scoundrel [369]

The answer to your question is,

D. Toggle Filter. You don't want to remove the filter, you just want to see the difference.

-Mabel <3

5 0
3 years ago
Read 2 more answers
What is the output of this Python code?
Simora [160]

Answer:

True

Explanation:

in function guess:- a = x; b = y; c = z

so 45 > 31 AND 45 < 38

since both the stements are true

True is printed

8 0
2 years ago
in python i wrote a function where if the user inputs a certain word the function repeats over again, since the function aaks fo
Colt1911 [192]
Check out the counter set
4 0
2 years ago
. :
Rudik [331]

Answer:

Yes.  I completely agree.

Explanation:

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

Yes.  I completely agree.

7 0
2 years ago
Other questions:
  • A powerpoint ________ is a set of unified design elements.
    5·1 answer
  • When a person buys something from an app store, the cost of the item is charged to a credit card whose number often is known by
    5·1 answer
  • Which is a correctly formatted Python tuple?
    9·1 answer
  • Each processor core on a multi core processor generally runs faster than a single core processor
    14·2 answers
  • To color the h2 heading, what tag would you use?
    6·1 answer
  • If your internet were to go out, what steps would you take to troubleshoot to restore your service?
    15·1 answer
  • What happens when you apply a theme to a form?
    14·1 answer
  • PLEASE PLEASE PLEASE PLEASE help me Im completly lost will give brainliest and 50 points
    8·2 answers
  • Which one of these are a valid IPv4 address?
    8·1 answer
  • Question 12 (5 points)
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!