• Register
0 votes
25 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?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

0 votes
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]);

 

11 6 4
34,950 points

Related questions

1 vote
1 answer 20 views
20 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.
asked Mar 29, 2020 Gavin 15.3k points
0 votes
1 answer 11 views
11 views
Illustrate with an example
asked Nov 16, 2020 jagruthi 680 points
0 votes
2 answers 361 views
361 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?
asked Mar 21, 2020 LizzyM 6.1k points
0 votes
1 answer 10 views
10 views
Problem: Hi there! I have started learning java just recently and I found a problem in a programming exercise in which I have to find the second largest number in a given array using programming. I know how to find the largest number, but I am facing difficulty ... number. Can anybody here help me solve the problem? Also, provide the example program so that I can understand it better. Thanks!
asked Jan 2 Code Learner 5.3k points
1 vote
1 answer 28 views
28 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.
asked Mar 29, 2020 Gavin 15.3k points
0 votes
1 answer 4 views
4 views
Can anyone please explain what is wrong with this and what I need to do to fix it?
asked Dec 19, 2020 TeamScript 9.2k points
0 votes
1 answer 34 views
0 votes
1 answer 28 views
28 views
Problem: We can locate the second biggest number in an exhibit in java by arranging the cluster and restoring the second biggest number. We should see the full guide to locate the second biggest number in java exhibit.
asked Nov 5, 2020 Mashhoodch 5.6k points
3 votes
1 answer 21 views
21 views
Problem: Hello good souls, I am a new student of Java. I just started learning and trying to solve java problems. Right now, I am working with the arrays. I can do some basic things with an array. I am finding something more advance problems of an array. Thus I thought to find the ... in java? Let&rsquo;s say I have an array Integer[] num = { 2, 4, 6, 5, 8 }; Thanks in advance for your effort.
asked Mar 23, 2020 Gavin 15.3k points
0 votes
1 answer 93 views
93 views
Problem: Hi dear friends is there any way to find out the sum of total element of array which is equal to given number. Please suggest any example.
asked Nov 6, 2020 Mubashi-Question 1.7k points