info@meritcampus.com    +91-85006-22255
...
`

Write a program to get the topper of maths from given array

Input (String Array, Integer Array) Output (String)
{"Kavya", "Navya", "Divya", "Rajesh", "Vinod"},
{80, 76, 85, 92, 89}
"Rajesh"
{"Roopa", "Reena", "Raj", "Lucky"},
{97, 45, 77, 85}
"Roopa"
{35, 88, 67, 99, 100}
{"Krish", "Meena", "Jyothi"},
{78, 56, 45}
"Krish"
{"Harika", "Swetha", "Sneha", "Sukumar"},
{35, 66, 47, 39}
"Swetha"

``` class MathsTopper {     public static void main(String s[])    {        String names[] = {"Kavya", "Navya", "Divya", "Rajesh", "Vinod"};        int mathsMarks[] = {80, 76, 85, 92, 89};        System.out.println("The maths topper is " + getMathsTopper(names, mathsMarks));    }         public static String getMathsTopper(String names[], int mathsMarks[])         { ```
```         } } ```
Topic:

### User comments below.All of them might not be correct.

first find the the maximum value index in mathsmarks[] array
and return a  name  from string[maximum value index]
example:
marks[]=(10{0},20{2},30{2}); {index number};
names[]={"a","b","c"};
here maximum value in in array marks is 30 and it index is 2
and maximum marks holders is names[2] is "c";
reurn that name;

Posted by Goutham Singarapu    2015-02-03 08:27:19

here u r given an array of student name and thwir corresponding mrks in anothr arry.. we have to find th topper... for this we will have to traverse the marks array .....and find the maximum value... to do this take a variabl max=marks[0],pos=0 and den take a loop a=1 to end of array....  now if max<marks[a] den max=marks[a] and pos=a.... end loop... this will compute the max value of array ..... then print the corresponding name of max marks wich is at name[pos] .......return name[pos]

Posted by Asma Mujtaba Khan    2015-02-03 09:37:42

--Here,we have to find maximum of integer array and then the index at which maximum element is present we have ro use that index for displaying name from first array.

--put 1st element in max variable.
-->max=array[0]

--run loop from 1st element till the last element of array.
-->for(int i=1;i<=mathsMarks.length-1;i++)

--we have to check if element of max is smaller than array
element then we have to put grater array element in max
and position oh=f that element in pos variable else 0.
-->if(max<mathsMarks[i])
{
max=mathsMarks[i];
pos=i;
}
else
max=0

--In "pos" we get position element which is greatest from
mathsMarks array.using that index to find out name from first array as follows:

--> return names[pos];//name of student with highest marks in
maths

Posted by Mânïshå Mùlchåndânï    2015-02-03 18:57:54

This dose is now closed and the winners are Goutham Singarapu,  for 'First Correct Comment', Asma Mujtaba Khan,  for 'Second Correct Comment'. The 'lucky liker' is Gopinath Manchikanti. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2015-02-04 04:52:42