ENROLLMENT_NO:-236010307006 BATCH:-CO1
NAME:-Badat Rizwan Ishak
Practical:-02
Aim:-Write a program in Java to find maximum of three
numbers using conditional operator.
Input:-
import [Link];
public class P2_AOOP006 {
public static void main(String[] ar)
int a,b,c;
scanner s1= new scanner([Link]);
[Link]("enter value of a:" );
a=[Link]();
[Link]("enter value of b:" );
b=[Link]();
[Link]("enter value of c:" );
c=[Link]();
int ans=a>b?(a>c?a:c):(b>c?b:c);
[Link]("greater number is"+ans);
}
Output:-
}
Advanced Object Oriented Programming(4340701) Page 1
ENROLLMENT_NO:-236010307006 BATCH:-CO1
NAME:-Badat Rizwan Ishak
Practical:-03
Aim:- Write a program in Java to reverse the digits of a number
using while loop
Input:-
import [Link];
public class P3_AOOP112 {
public static void main(String[] a)
int n;
[Link]("enter num:");
Scanner sc= new Scanner([Link]);
n=[Link]();
[Link]("reverse num is :");
while(n>0)
int ans= n%10;
[Link](ans);
n=n/10;
}
Output:-
Advanced Object Oriented Programming(4340701) Page 2
ENROLLMENT_NO:-236010307006 BATCH:-CO1
NAME:-Badat Rizwan Ishak
Practical:-04
Aim:- Write a program in Java to add two 3*3 matrices.
Input:-
import [Link];
public class multi112 {
public static void main(String[] arg)
int a[][]=new int [3][3];
int b[][]=new int [3][3];
int add[][]=new int [3][3];
Scanner sc=new Scanner([Link]);
[Link]("enter value of frist Matrix:");
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
a[i][j]=[Link]();
[Link]("enter value of second matrix:");
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
b[i][j]=[Link]();
Advanced Object Oriented Programming(4340701) Page 3
ENROLLMENT_NO:-236010307006 BATCH:-CO1
NAME:-Badat Rizwan Ishak
}
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
add[i][j]=a[i][j]+b[i][j];
[Link]("addition of two amtrix:");
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
[Link](add[i][j]+" ");
[Link]();
Output:-
Advanced Object Oriented Programming(4340701) Page 4
ENROLLMENT_NO:-236010307006 BATCH:-CO1
NAME:-Badat Rizwan Ishak
Practical:-05
Aim:- Write a program in Java to generate first n prime numbers.
Input:-
import [Link];
public class first_n_prime {
public static void main(String args[])
int number,count=0,n=0,i=1,j=1;
Scanner sc=new Scanner([Link]);
[Link]("Enetr n");
number=[Link]();
while (n<number
j=1;
count=0;
while(j<=i)
if(i%j==0)
count++;
j++;
if(count==2)
Advanced Object Oriented Programming(4340701) Page 5
ENROLLMENT_NO:-236010307006 BATCH:-CO1
NAME:-Badat Rizwan Ishak
[Link](i+"");
n++;
i++;
Output:-
Advanced Object Oriented Programming(4340701) Page 6