Java question Write a method that returns the integer with t
Solution
import java.util.*;
class Finder
{
public int display(int[] b,int limit)
{
System.out.println(\"inside the method\");
int max=0;
int max_pos=0;
int x,y;
for(int j=0;j < limit;j++)
{
for(int k=j+1;k < limit;k++)
{
if ( Math.abs(b[j]) >= Math.abs(b[k]))
{
int t=b[j];
b[j]=b[k];
b[k]=t;
}
}
}
return b[limit-1];
}
}
public class Sample
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int a[]=new int[100];
System.out.println(\"enter the no of elements in a array\");
int n=in.nextInt();
for(int i=0;i<n;i++)
{
a[i]=in.nextInt();
}
Finder ob=new Finder();
int r=ob.display(a,n);
System.out.println(\"the maximum absolute is \" + r);
}
}
