Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

largest number in an array in java

public class LargestNum {
   
    public static void main(String[] args) {
        int arrayA[]={1,2,5,6,3,2,300,50,5000};  
        int arrayB[]={44,66,99,77,33,22,55};  
        System.out.println("Largest: "+caculateLargestNum(arrayA,arrayA.length));  
        System.out.println("Largest: "+caculateLargestNum(arrayB,arrayB.length));  
    }
  
        public static int caculateLargestNum(int[] array, int total){  
        int cal;  
        for (int i = 0; i < total; i++)   
                {  
                    for (int j = i + 1; j < total; j++)   
                    {  
                        if (array[i] >array[j])   
                        {  
                            cal =array[i];  
                            array[i] = array[j];  
                            array[j] = cal;  
                        }  
                    }  
                }  
               return array[total-1];  
        }  
       
}
Comment

PREVIOUS NEXT
Code Example
Java :: printing array in descending order 
Java :: implement elasticsearch filter in java 
Java :: unparseable date android 
Java :: ExpandableLayout in android 
Java :: Java Creating LinkedHashSet from Other Collections 
Java :: Java @FunctionalInterface annotation 
Java :: linearview 2 items next to each other 
Java :: copy one string to another without using any loops or assignment operator 
Java :: how to select multiple non-consecutive words on mac 
Java :: java program operations by classes and objects 
Java :: set length java 
Java :: java code to implement hybrid interface 
Java :: Get and set method uml 
Java :: Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "EXCEPTION": invalid identifier 
Java :: how to generate and save image of layout in android 
Java :: Changing or Replacing Elements in java map 
Java :: JDA send DM 
Java :: sha 1 key throguh java is not working 
Java :: turn on device location android programmatically 
Java :: https://www.baeldung.com/java-stream-findfirst-vs-findany 
Java :: who was the mother of thomas elva edison 
Java :: android studio see what activity you came from 
Java :: current currency rates api 
Java :: how to create a udp protocol for transfer a big quantity of files java 
Java :: How to pass ArrayList of Objects from one to another activity using Intent in android? 
Java :: bebra 
Java :: bakht k takht sy yaklakht utara hwa shaks tuny dekha hai kbi jeet k hara hwa shaks in urdu 
Java :: hadoop fs get size of directory java 
Java :: c# param.ExStyle equivalent in java 
Java :: java gui refresh frame 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =