0

```
Q.Write a program using 2D array. A company manufactures three
products P1, P2 and P3. Company has hired five salesman. Each
salesman sell all three products. Accept from user number of each
product sold by each salesman. Find the product whose sale was
largest.Also find the salesman whose sales were the least.
-------------------------------------------------------------------------------------------------------
THIS IS THE QUESTION.I TRIED A LOT AND CAME UP WITH THIS SOLUTION BUT STILL GETTING ERRORS....PLZ HELP
import java.util.*;
class Salesman
{
public static void main(String args[])
{
int i,j;
int s[][]=new int[5][4];
int salesman_hs=s[0][3];
int salesman_ind=0;
int max_prod=0;
int prod_ind=0;
int sum;
Scanner sc= new Scanner(System.in);
for(i=0;i<=4;i++)
{
System.out.println("Enter product sold by salesman"+(i+1));
for(j=0;j<=2;j++)
{
System.out.println("Enter sale for product"+(j+1));
s[i][j]=sc.nextInt();
s[i][3]=s[i][3]+s[i][j];
}
if(s[i][3]>salesman_hs)
{
salesman_hs=s[i][3];
salesman_ind=i;
}
}
for(i=0;i<=2;i++)
{
sum=0;
for(j=0;j<=4;j++)
{
sum=sum+s[j][i];
}
if(max_prod<sum)
{
max_prod=sum;
prod_ind=i;
}
}
}
System.out.println("p1\t p2\t p3\t total");
for(i=0;i<=4;i++)
{
for(j=0;j<=3;j++)
{
System.out.print(s[i][j]+"\t");
}
System.out.println();
}
System.out.println("\n Salesman"+(salesman_ind+1)+"has highest sales of"+salesman_hs);
System.out.println("Product"+(prod_ind+1)+"has the highest sales of"+max_prod);
}
```