# 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
1 answer 12 views
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.
2 answers 85 views
85 views
Problem: I am new at java programming and I used a method: java.io.File>list( which is used to obatain the list of files and and directories in the specified directory defined by its path name. This list of files are stored in a string array. If the length of this string ... .out.println("The directory " + directory.getPath() + " is empty"); } } But it does not seems to work can anyone help?
1 vote
1 answer 12 views
12 views
Problem: I am trying to finding the largest number in an array c++ Every time I am trying my code is printing all the values of the array instead of the largest one. I might be doing something wrong inside my iteration. Do you have any idea to do it more easily and efficiently? I&rsquo;d love to hear from you guys. Please shar your ideas about this. Thanks.