# how to find the largest number in an array java.txt

15 views
```I am new at java programing, I have an assginment about how to find largest number in array and I start coding on my own and i wrote a program given bellow :
```
``````int size ;
int array[] = {10, 20, 25, 63, 96, 57};
size = array.length;

for(int i = 0; i<size; i++ ){

for(int j = i+1; j<size; j++){
if(array[i]>array[j]){
size = array[i];
}

}
System.out.println("Third largest element is:: "+array[size])

}``````

but it is not running, what should I do now?

```Compare the first two elements of the array
If the first element is greater than the second swap them.
Then, compare 2nd and 3rd elements if the second element is greater than the 3rd swap them.
Repeat this till the end of the array.
After sorting an array print the 1st element from the end of the array.
After sorting an array print the 1st element from the end of the array:
```
``````int temp, size;
int array[] = {10, 20, 25, 63, 96, 57};
size = array.length;

for(int i = 0; i<size; i++ ){
for(int j = i+1; j<size; j++){
if(array[i]>array[j]){
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
System.out.println("Third largest element is:: "+array[size-1]);
``````

## Related questions

1 vote
12 views
Problem: Hello Kodlogs, I have got a question from my fellow (java learner) friend and the question is: find the largest number in an array java I know about the array and I can print all the values sequentially. Moreover, I can add two different values of an array in ... Could any of you please give me a proper solution and tell me how to find the largest number in an array java? Thanks to all.