/**
* Find the minimum and maximum number in a given array.
*
* Approach: we can pick an element from array and compare with the min and max value
*
*
*/
public class MinMaxNumber {
public static void main(String[] args) {
int arr[] = {1100,10,3,5,8,1,5,9,23,56,0,90,54};
int min,max;
min=max= arr[0];
for(int i =1 ; i<arr.length;i++){
if (min > arr[i]){ // comparing the number for min value
min= arr[i];
}
if(max < arr[i]){ // comparing the number for max value
max=arr[i];
}
}
System.out.println("Min value = " + min);
System.out.println("Max value = " + max);
}
}
/* output
Min value = 0
Max value = 1100
Explore the Latest in Tech & Automation: Android, iOS, Mobile Testing with Appium, Web Automation using Selenium, Python & Java Programming, Robot Framework, Shell & PowerShell Scripting, QA Tools, Spring Boot Development, Agentic AI Innovations, Free Software Resources, and Expert Tips on Designing Scalable Automation Frameworks.
Sunday, June 7, 2015
Java : Program to find the minimum and maximum number in a given array.
Subscribe to:
Post Comments (Atom)
Robot Framework : Sample code to verify if Robot Framework is installed properly ? - part2
Sample code to verify if Robot Framework is installed properly ? 1. Create a file name test.robot and save it. *** Test Cases *** Sample ...
-
How to find the UDID of Android Device What is UDID : It stands for Unique Device Identifier. UDID is required duri...
-
How to change language of device using commandLine Changing language in Android device on-the fly is needed when we are running or exe...
-
How to get the package name of Android application There are multiple ways in which we can obtain the package name of Android .apk file. ...
No comments:
Post a Comment