finding min and max from given number in java
Java
Scanner input = new Scanner(System.in);
// Minimum And Maximum
int count = 0;
int min = 0;
int max = 0;
boolean bugSolved = true;
/* or we can use :
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
*/
while (true){
int cnt = count++;
System.out.print("Enter Number #"+(cnt+1)+": ");
boolean isValid = input.hasNextInt();
if(isValid){
int num = input.nextInt();
/* if (bugSolved){
bugSolved = false;
min = num;
max = num;
} # Just remove this condition and
boolean (bugSolved) at the top, if you use
int min = Integer.MAX_VALUE and int max =
Integer.MIN_VALUE */
if (num < min) {
min = num;
}else if (num > max){
max = num;
}
}else{
System.out.println("Invalid input..");
break;
}
input.nextLine();
}
System.out.println("Min Number : " + min);
System.out.println("Max Number : " + max);public static double arrayMax(double[] arr) {
double max = Double.NEGATIVE_INFINITY;
for(double cur: arr)
max = Math.max(max, cur);
return max;
}import java.util.Random;
public class Main {
public static void main(String[] args) {
int a[] = new int [100];
Random rnd = new Random ();
for (int i = 0; i< a.length; i++) {
a[i] = rnd.nextInt(99-0)+0;
System.out.println(a[i]);
}
int max = 0;
for (int i = 0; i < a.length; i++) {
a[i] = max;
for (int j = i+1; j<a.length; j++) {
if (a[j] > max) {
max = a[j];
}
}
}
System.out.println("Max element: " + max);
}
}import java.util.Arrays;
public class apples {
public static void main(String[] args) {
int a[] = {2,5,3,7,8};
Arrays.sort(a);
int min =a[0];
System.out.println(min);
int max= a[a.length-1];
System.out.println(max);
}
}private static int findMin(int[] array) {
int min = array[0];
for(int i=1;i<array.length;i++) {
if(min > array[i]) {
min = array[i];
}
}
return min;
}
Also in Java:
- Title
- query java persistence
- Category
- Java
- Title
- java initialize string array
- Category
- Java
- Title
- Method used for getting metadata of a database in jdbc
- Category
- Java
- Title
- jbutton open jframe java
- Category
- Java
- Title
- java binary exponentiation
- Category
- Java
- Title
- java implement interface
- Category
- Java
- Title
- convert localdatetime to localdate
- Category
- Java
- Title
- bukkit java get max players
- Category
- Java
- Title
- test function that call a function javascrip
- Category
- Java
- Title
- how to import jframe in java
- Category
- Java
- Title
- log4j with spring boot restful services
- Category
- Java
- Title
- java string regexp replace
- Category
- Java
- Title
- two dimensional array in java example program
- Category
- Java
- Title
- JSONObject java
- Category
- Java
- Title
- java get int from double without rounding
- Category
- Java
- Title
- what is a float java
- Category
- Java
- Title
- java import text file into arraylist
- Category
- Java
- Title
- cannot lock java compile cache as it has already been locked by this process
- Category
- Java
- Title
- generate all prime number less than n java (fastest method)
- Category
- Java
- Title
- LocalRegistry java rebind() java8
- Category
- Java
- Title
- java copy array
- Category
- Java
- Title
- working with buttons in applet java
- Category
- Java
- Title
- write an infinite loop java
- Category
- Java
- Title
- date format in java
- Category
- Java
- Title
- hide elements android
- Category
- Java
- Title
- hello world java
- Category
- Java
- Title
- java string to char array
- Category
- Java
- Title
- java check if directory exists
- Category
- Java
- Title
- java throws multiple exceptions
- Category
- Java
- Title
- java infinitew recursion
- Category
- Java
- Title
- java for loop add multiple declarations
- Category
- Java
- Title
- split with scquere braket in java
- Category
- Java
- Title
- validation list empty java
- Category
- Java
- Title
- how to create an array list in java
- Category
- Java
- Title
- what is a variable in java
- Category
- Java
- Title
- java iterate through map
- Category
- Java
- Title
- java get size of array
- Category
- Java
- Title
- blurview android github
- Category
- Java
- Title
- scanner check if int
- Category
- Java
- Title
- convert char to string java
- Category
- Java
- Title
- Java array multidimensional hashcode
- Category
- Java
- Title
- vector in java
- Category
- Java
- Title
- array in line java
- Category
- Java
- Title
- spigot custom join message
- Category
- Java
- Title
- how to end a program in an if statement java
- Category
- Java
- Title
- java read each lines in file
- Category
- Java
- Title
- java string to lower case
- Category
- Java
- Title
- while loops java
- Category
- Java
- Title
- how to remove all whitespace from string java
- Category
- Java
- Title
- java convert char to int
- Category
- Java
- Title
- reading string after double in java
- Category
- Java
- Title
- junit meaning in java
- Category
- Java
- Title
- java foreach
- Category
- Java
- Title
- taking string input in java
- Category
- Java
- Title
- print in java
- Category
- Java
- Title
- localdate to string java
- Category
- Java
- Title
- double parse jtextfield
- Category
- Java
- Title
- what it means when create final variable in java
- Category
- Java
- Title
- how to exit a for loop in java
- Category
- Java
- Title
- java code to get all leaf nodes of a xml
- Category
- Java
- Title
- java define a generic class that produces
- Category
- Java
- Title
- get certain character from string java
- Category
- Java
- Title
- java list contains object with property
- Category
- Java
- Title
- has been compiled by a more recent version of the Java Runtime (class file version 56.0), this version of the Java Runtime only recognizes class file versions up to 55.0
- Category
- Java
- Title
- spring framework iterate
- Category
- Java
- Title
- sdkmanager JAVA_HOME invalid directory
- Category
- Java
- Title
- java min function
- Category
- Java
- Title
- sort elements with sortedset
- Category
- Java
- Title
- java replace all html tags
- Category
- Java
- Title
- how to check the lines in a file java scanner
- Category
- Java
- Title
- map with insertion order preserved java
- Category
- Java
- Title
- how to fill a list with a single value java
- Category
- Java
- Title
- java regex replace all characters before
- Category
- Java
- Title
- how to close a jframe in java with an if statement
- Category
- Java
- Title
- java hashmap get value
- Category
- Java
- Title
- java count substring occurrences in string
- Category
- Java
- Title
- java 8 loop in map
- Category
- Java
- Title
- how to quicksort a string array in java
- Category
- Java
- Title
- java file path linux
- Category
- Java
- Title
- how to write queries in java
- Category
- Java
- Title
- how to create a linked list in java
- Category
- Java
- Title
- java sleep in code
- Category
- Java
- Title
- jq selector body
- Category
- Java
- Title
- boolean java.lang.String.equals(java.lang.Object)' on a null object reference
- Category
- Java
- Title
- import java.util.*;
- Category
- Java
- Title
- java clone method
- Category
- Java
- Title
- string to char in java
- Category
- Java
- Title
- D/NetworkSecurityConfig: No Network Security Config specified, using platform default
- Category
- Java
- Title
- how to ask user for his location in android
- Category
- Java
- Title
- raise number to power java
- Category
- Java
- Title
- a recursive function that calculates the greatest common divisor from user's input in java
- Category
- Java
- Title
- string remove last character
- Category
- Java
- Title
- difference between compile and execute in java
- Category
- Java
- Title
- How to chage font progrmatically
- Category
- Java
- Title
- java check if file exists
- Category
- Java
- Title
- on click android studio not working
- Category
- Java
- Title
- récupérer les données d un liste java
- Category
- Java
- Title
- how to create java jframe in eclipse
- Category
- Java
- Title
- java fullscreen jframe
- Category
- Java
- Title
- java parse json
- Category
- Java