how to get the max value of an array java
Java
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);
}
}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.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);
}
}
Also in Java:
- Title
- how to calculate exponential in java
- Category
- Java
- Title
- how to declare a linked list in java
- Category
- Java
- Title
- firebase connecten
- Category
- Java
- Title
- java singleton implementation
- Category
- Java
- Title
- kotlin jsonobject get nested
- Category
- Java
- Title
- how to make an arraylist java
- Category
- Java
- Title
- how to create a 2d arraylist java
- Category
- Java
- Title
- java string split underscore
- Category
- Java
- Title
- android how to split string
- Category
- Java
- Title
- gravity in java
- Category
- Java
- Title
- java.lang.ClassCastException: cannot be cast to javax.servlet.Servlet
- Category
- Java
- Title
- android how to switch between activities
- Category
- Java
- Title
- java methods
- Category
- Java
- Title
- swapping of two numbers in java
- Category
- Java
- Title
- insertion sort doubly linked list java
- Category
- Java
- Title
- number of matches regex java
- Category
- Java
- Title
- how to convert char to uppercase java
- Category
- Java
- Title
- abstract class in java
- Category
- Java
- Title
- arraylist get last
- Category
- Java
- Title
- how to make a pre set list java
- Category
- Java
- Title
- detect tv remote keys andoid studio
- Category
- Java
- Title
- break for loop java
- Category
- Java
- Title
- using java 8 stream to process data in java
- Category
- Java
- Title
- error attribute fabattached not found
- Category
- Java
- Title
- how to get token oauth2.0 java example response
- Category
- Java
- Title
- best companies to workk in
- Category
- Java
- Title
- faire un timer en java
- Category
- Java
- Title
- hello world in java
- Category
- Java
- Title
- java substring
- Category
- Java
- Title
- split method in java
- Category
- Java
- Title
- java foreach
- Category
- Java
- Title
- java for each loop
- Category
- Java
- Title
- java array to arraylist
- Category
- Java
- Title
- get drawable with string android java
- Category
- Java
- Title
- system.in example in java
- Category
- Java
- Title
- Java array equals
- Category
- Java
- Title
- java set value of arraylist
- Category
- Java
- Title
- basic java coding
- Category
- Java
- Title
- how to declare string array in java
- Category
- Java
- Title
- convert string to array java
- Category
- Java
- Title
- array methods in java
- Category
- Java
- Title
- java get icon for file type
- Category
- Java
- Title
- processing string to int
- Category
- Java
- Title
- java how to show an array
- Category
- Java
- Title
- replace all punctuation in string java
- Category
- Java
- Title
- java 8 collect multiple lists into single list
- Category
- Java
- Title
- java how to iterate through a arraylist
- Category
- Java
- Title
- java array check duplicates
- Category
- Java
- Title
- get cursor position in textarea java
- Category
- Java
- Title
- binary to octal conversion java program
- Category
- Java
- Title
- how to split a string in java
- Category
- Java
- Title
- android get distance between two locations kotlin
- Category
- Java
- Title
- if en une seul ligne java
- Category
- Java
- Title
- java print syntax
- Category
- Java
- Title
- random code
- Category
- Java
- Title
- how to create an abstract method in java
- Category
- Java
- Title
- Java app development
- Category
- Java
- Title
- double to string java
- Category
- Java
- Title
- récupérer les données d un liste java
- Category
- Java
- Title
- prime factorization java
- Category
- Java
- Title
- integer to string java
- Category
- Java
- Title
- how to create a thread local variable in java
- Category
- Java
- Title
- java random number in range
- Category
- Java
- Title
- remove last character from string java
- Category
- Java
- Title
- teimpo en segundos java
- Category
- Java
- Title
- on click android studio not working
- Category
- Java
- Title
- java compareto
- Category
- Java
- Title
- convert java list to array
- Category
- Java
- Title
- mutable string in java
- Category
- Java
- Title
- online money transfer andhra bank
- Category
- Java
- Title
- final variables in java
- Category
- Java
- Title
- primitive and non primitive data types in java
- Category
- Java
- Title
- string to char in java
- Category
- Java
- Title
- http client java
- Category
- Java
- Title
- java count substring occurrences in string
- Category
- Java
- Title
- String array into LinkedList java
- Category
- Java
- Title
- how to make generic arraylist in java
- Category
- Java
- Title
- leap year program in java
- Category
- Java
- Title
- spring org.springframework.stereotype not visible
- Category
- Java
- Title
- java for
- Category
- Java
- Title
- java get folder content
- Category
- Java
- Title
- java hashmap syntax
- Category
- Java
- Title
- Building a maven EAR project and specifying the configuration of which projects to include, what is the element in the plugin configuration that contains Enterprise Java Bean Projects:
- Category
- Java
- Title
- java infinitew recursion
- Category
- Java
- Title
- java min function
- Category
- Java
- Title
- java create unmodifiable list
- Category
- Java
- Title
- copy file with byte java
- Category
- Java
- Title
- same method name with different arguments
- Category
- Java
- Title
- java collapse string array
- Category
- Java
- Title
- java stream order by property
- Category
- Java
- Title
- java while loop break
- Category
- Java
- Title
- html top padding
- Category
- Java
- Title
- how to remove all special characters from a string in java
- Category
- Java
- Title
- how to push an element in hashset java
- Category
- Java
- Title
- java type casting
- Category
- Java
- Title
- how to change actionbar color in android programmatically
- Category
- Java
- Title
- two pointer approach java
- Category
- Java
- Title
- while loops java
- Category
- Java
- Title
- write file from a specific location in java
- Category
- Java
- Title
- time conversion solution
- Category
- Java