0

I am running this program class Practice{

public static int MaxProduct(int[] array){
int product = 0;
int n= array.length;
for(int i=0; i<n;i++){
for(int j=i+1;j<n;j++){
if(array[i]*array[j] > product){
product =array[i]*array[j];
}
}
}
return product;
}


public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of array");
int n = sc.nextInt();
System.out.println("Enter the numbers");
int[] array = new int[n];
for(int i=0; i<n;i++){
   array[i]= sc.nextInt();
}
System.out.println(MaxProduct(array));
}
} 

and it runs fine. However when I create an object to Practice class and call MaxProduct method as

Practice p = new Practice();
p.MaxProduct(array);
System.out.println(p);

I get the output as practice.Practice@42a57993 . Can someone tell me what is wrong here ?

Franky
  • 1
  • 1

0 Answers0