The break statement can be used to eliminate the use of certain (flag) variables.
<h3>What is break statement?</h3>
A break statement is used to terminate the execution of the nearest enclosing for, do, switch, or while statement in which it appears.
The main purpose of break statement is to destroy the loop as soon as possible. For example if the given code asks a use input a integer number x. If x is divisible by 5, the break statement is executed and this causes the exit from the loop.
The advantage of break statement is it stops the case testing inside the block and break may be used within loops to alter control flow.
Therefore, the break statement can be used to eliminate the use of certain (flag) variables.
Learn more break statement here:
brainly.com/question/15082759
#SPJ4
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:
- This is implemented in Java Programming Language
- Two Methods are created returnMax(Returns the Maximum Value of the five numbers) and returnMin(Returns the minimum of the five numbers)
- In the Main method, the user is prompted to enter five numbers
- The five numbers are saved into an array of integers
- The returnMax and returnMin methods are called and passed the array as parameter.
- The entire array of numbers inputted by the user as well the Max and Min are printed