Slip 1
Slip 1
import java.util.*;
class prime
{
public static void main(String args[])
{
int i,j,count,n;
n=Integer.parseInt(args[0]);
int a[]=new int[n];
System.out.println("Enter array elements :");
Scanner s=new Scanner(System.in);
for(i=0;i<n;i++)
{
a[i]=s.nextInt();
}
System.out.println("Prime Numbers are :");
for(j=0;j<=n;j++)
{
count=0;
for(i=1;i<=a[j];i++)
{
if(a[j]%i==0)
{
count++;
}
}
if(count==2)
{
System.out.println(a[j]+" ");
}
}
}
}
Q.2
import java.util.*;
abstract class staff
{
protected int id;
protected String name;
staff(int a,String b)
{
this.id=a;
this.name=b;
}
}
class officestaff extends staff
{
String dep;
officestaff(int a,String b,String c)
{
super(a,b);
this.dep=c;
}
void display()
{
System.out.println("ID :"+id);
System.out.println("Name :"+name);
System.out.println("Department Name :"+dep);
System.out.println(" ");
}
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
System.out.println("Enter the number of employees :");
int N=s.nextInt();
officestaff os[]=new officestaff[N];
for(int i=0;i<N;i++)
{
System.out.println("Enter ID :");
int a=s.nextInt();
System.out.println("Enter Name :");
String n=s.next();
System.out.println("Enter Department name :");
String d=s.next();
os[i]=new officestaff(a,n,d);
os[i].display();
}
}
}