Question

Create a java program.Input 10 integers in the main function using for loop. Determine the largest...

Create a java program.Input 10 integers in the main function using for loop. Determine the largest and smallest number. Create and call the following methods.
max() --> to determine the largest number
--> must have two (2) parameters only
   --> must return integer
min() --> to determine the smallestnumber
--> must have two (2) parameters only
   --> must return integer
display the result in the main function

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Copy to your IDE for a better view!

CODE:

import java.io.*;
import java.util.Scanner;
class MaxMin {
   public static void main (String[] args) {
       int a[]; //declaring array a
       a=new int[10]; //allocating memory of 10 elements
       Scanner in = new Scanner(System.in);
       for(int i=0;i<10;i++)
       {
       a[i] = in.nextInt();//taking input from user
       }
       int M=max(a,10);//calling max function
       System.out.println("Max number is "+ M);
       int m=min(a,10);//calling minimum function
       System.out.println("Min number is "+ m);
   }
   public static int max(int a[],int n)
   {
   int M=a[0];// asuming first number as maximum
   for(int i=1;i<n;i++)
   {
   if(a[i]>M)//if ith number is more than assumed
   {
   M=a[i];//change M to ith number
   }
   }
   return M;
   }
   public static int min(int a[],int n)
   {
   int m=a[0];// asuming first number as minimum
   for(int i=1;i<n;i++)
   {
   if(a[i]<m)//if ith number is less than assumed
   {
   m=a[i];//change M to ith number
   }
   }
   return m;
   }
}

code screenshot:

Input :

output:

If any queries do comment!

Upvote, Please!

All the best!

Add a comment
Know the answer?
Add Answer to:
Create a java program.Input 10 integers in the main function using for loop. Determine the largest...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create two java programs. The first will ask the user to enter three integers. Once the...

    Create two java programs. The first will ask the user to enter three integers. Once the three integers are entered, ask the user to enter one of three functions. The “average” if they want the average of the three numbers entered, enter “min” if they want the minimum and “max” if they want the maximum. Display the answer. Ask the user if they want to calculate another function for the three numbers. If so, loop and ask what function they...

  • This is JAVA language Create a .java class called MoreArrayFun.java with only a main method. This...

    This is JAVA language Create a .java class called MoreArrayFun.java with only a main method. This program will use the ArrayManager class. The final version of the program is described below, but initially use it to test your ArrayManager class as you write it. Complete the ArrayManager class as specified below: The class will have exactly two instance variables:  An array of integers  A count of the number of elements currently in the array The class will have...

  • Write a complete C++ program that at least consists of the main() function and a recursive...

    Write a complete C++ program that at least consists of the main() function and a recursive function gcd() with return value. Define function gcd() with two and only two parameters that calculates the greatest common divider of two given parameters. Hint: use the difference between two parameters or the remainder obtained using one parameter divide the other. In main() Read 2 positive integers with proper prompt. Call gcd() with proper syntax. Display the result, i.e. the greatest common divider of...

  • In Java: Create an array of Integers with 10 elements, loop (use a for loop) through...

    In Java: Create an array of Integers with 10 elements, loop (use a for loop) through the array of integers printing their values to the screen. Create an array of Strings with 10 elements, loop (use a for loop) through the array of Strings printing their values to the screen. Finally, create an ArrayList of Integers. Use the loop from part 1 above and add each integer as you print it to the ArrayList as well, then start a final...

  • In this lab, you will create one class named ArrayFun.java which will contain a main method...

    In this lab, you will create one class named ArrayFun.java which will contain a main method and 4 static methods that will be called from the main method. The process for your main method will be as follows: Declare and create a Scanner object to read from the keyboard Declare and create an array that will hold up to 100 integers Declare a variable to keep track of the number of integers currently in the array Call the fillArray method...

  • #include <stdio.h> // Define other functions here to process the filled array: average, max, min, sort,...

    #include <stdio.h> // Define other functions here to process the filled array: average, max, min, sort, search // Define computeAvg here // Define findMax here // Define findMin here // Define selectionSort here ( copy from zyBooks 11.6.1 ) // Define binarySearch here int main(void) { // Declare variables FILE* inFile = NULL; // File pointer int singleNum; // Data value read from file int valuesRead; // Number of data values read in by fscanf int counter=0; // Counter of...

  • Java generics Write a program that calls a method to multiply two integers and return the...

    Java generics Write a program that calls a method to multiply two integers and return the integer result. Modify the program to make the method generic, calling it with two generic data types and then returning the result in the same type which also has to be generic. Call the method two times, once with an integer and once with a double in your main program and display the results

  • Java Programming Write a method named isEven that accepts an integer argument. The method should return...

    Java Programming Write a method named isEven that accepts an integer argument. The method should return true if the argument is even, or false if not. The program’s main method should use a loop to generate a random integer. The number of random integers is provided by a user, who must enter a number greater than 10. The loop should then invoke the isEven method to determine whether each integer is even or odd, display the random number and the...

  • The main(int argc, char *argv[]) function will perform the following: • Evaluate whether value in argc...

    The main(int argc, char *argv[]) function will perform the following: • Evaluate whether value in argc is greater or equal to 3. • If it is not, then print the following message: Incorrect number of arguments - please call with assignment min max where assignment is the name of your executable and min/max define the range of numbers for your array. • If argc is ≥ 3 convert the values for min and max into integers and store them in...

  • In Java! NotMultipleStream: a stream that returns, in numeric order, integers that are not multiples of...

    In Java! NotMultipleStream: a stream that returns, in numeric order, integers that are not multiples of a certain value, starting from an initial value. The NotMultipleStream should behave like an IntegerStream, but it should include a NotMultipleFilter to filter out multiples of a certain value. The class will need the following methods and constructors: The constructor takes two integer values. The first is the base value and the second is the initial value. next: takes no input and returns an...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT