Position of largest prime number in matrix

import java.util.*;
class LargestPrime
{
public static void main(String[]args)throws Exception
{
Scanner d=new Scanner(System.in);
int m,n,p,q,i,j,k,c,lp;

System.out.println("Enter rows and columns for matrix: ");
m=d.nextInt();
n=d.nextInt();
int a[][]=new int[m][n];

System.out.println("Enter "+(m*n) + " elements: ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=d.nextInt();
}
}

lp = -1;

for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c = 0;
for(k=1; k<=a[i][j];k++){
if(a[i][j]%k == 0){
c++;
}
}
if( c==2 && lp < a[i][j])
lp = a[i][j];
}
}

if(lp != -1)
System.out.println("Largest Prime: "+lp);
else
System.out.println("No Prime number found!");

}//eom
}//eoc

No comments:

Post a Comment

any problem in any program comment:-

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...