JP Lab Solution
JP Lab Solution
Output:
Kanishk Chouhan
(0827CS201112)
Name of Student: Kanishk Chouhan Class: BE-II YEAR
Enrollment No: 0827CS201112 Batch:2020-24
Date of Experiment Date of Submission Submitted on:
Remarks by faculty: Grade:
Signature of student: Signature of Faculty:
Kanishk Chouhan
(0827CS201112)
Name of Student: Kanishk Chouhan Class: BE-II YEAR
Enrollment No: 0827CS201112 Batch:2020-24
Date of Experiment Date of Submission Submitted on:
Remarks by faculty: Grade:
Signature of student: Signature of Faculty:
Kanishk Chouhan
(0827CS201112)
Name of Student: Kanishk Chouhan Class: BE-II YEAR
Enrollment No: 0827CS201112 Batch:2020-24
Date of Experiment Date of Submission Submitted on:
Remarks by faculty: Grade:
Signature of student: Signature of Faculty:
1.*
**
***
****
*****
2. *****
****
***
**
*
1. public class JavaPyramid1{
public static void main(String[] args){
System.out.println("Kanishk Chouhan");
System.out.println("0827CS201112”);
for(int i=1; i<= 5 ;i++){
for(int j=0; j < i; j++){
System.out.print("*");
}
System.out.println("");
}
}
}
Kanishk Chouhan
(0827CS201112)
Name of Student: Kanishk Chouhan Class: BE-II YEAR
Enrollment No: 0827CS201112 Batch:2020-24
Date of Experiment Date of Submission Submitted on:
Remarks by faculty: Grade:
Signature of student: Signature of Faculty:
6. Write a program to find sum and average of the given number in an array.
public class CalculateArrayAverageExample {
public static void main(String[] args){
System.out.println("Kanishk Chouhan");
System.out.println("0827CS201112");
Kanishk Chouhan
(0827CS201112)
Name of Student: Kanishk Chouhan Class: BE-II YEAR
Enrollment No: 0827CS201112 Batch:2020-24
Date of Experiment Date of Submission Submitted on:
Remarks by faculty: Grade:
Signature of student: Signature of Faculty:
Kanishk Chouhan
(0827CS201112)
Name of Student: Kanishk Chouhan Class: BE-II YEAR
Enrollment No: 0827CS201112 Batch:2020-24
Date of Experiment Date of Submission Submitted on:
Remarks by faculty: Grade:
Signature of student: Signature of Faculty:
Kanishk Chouhan
(0827CS201112)
Name of Student: Kanishk Chouhan Class: BE-II YEAR
Enrollment No: 0827CS201112 Batch:2020-24
Date of Experiment Date of Submission Submitted on:
Remarks by faculty: Grade:
Signature of student: Signature of Faculty:
int num;
System.out.println("Program to demonstrate bubble sort");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the number of elements to be entered <10");
num=Integer.parseInt(br.readLine());
System.out.println("Enter the numbers to be sorted");
int arr[]=new int[10];
for(int i=0;i< num;i++){
arr[i]=Integer.parseInt(br.readLine());
}
System.out.println("The number you have entered:");
for(int i=0;i< num;i++){
System.out.println(arr[i]);
}
for(int i=0;i< num;i++){
for(int j=i+1;j< num;j++){
if(arr[i]>arr[j]){
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
System.out.println("The sorted numbers are");
for(int i=0;i< num;i++){
System.out.println(arr[i]);
}
}
}
Output
Kanishk Chouhan
(0827CS201112)
Name of Student: Kanishk Chouhan Class: BE-II YEAR
Enrollment No: 0827CS201112 Batch:2020-24
Date of Experiment Date of Submission Submitted on:
Remarks by faculty: Grade:
Signature of student: Signature of Faculty:
b)Subtraction.
c) Transpose.
d)Multiplication.
class Matrix{
public static void main(String args[]){
Kanishk Chouhan
(0827CS201112)
Name of Student: Kanishk Chouhan Class: BE-II YEAR
Enrollment No: 0827CS201112 Batch:2020-24
Date of Experiment Date of Submission Submitted on:
Remarks by faculty: Grade:
Signature of student: Signature of Faculty:
System.out.println("Kanishk Chouhan");
System.out.println("0827CS201112");
int i,j,k;
int mat1 [][]={ {1,2,3}, {4,5,6}, {7,8,9} };
int mat2 [][]={ {10,11,12}, {13,14,15}, {16,17,18} };
System.out.println("\nMatrix A:");
for(i=0;i< 3;i++){
for(j=0;j< 3;j++)
System.out.print("\t"+mat1[i][j]);
System.out.println("");
}
System.out.println("\nMatrix B:");
for(i=0;i< 3;i++){
for(j=0;j< 3;j++)
System.out.print("\t"+mat2[i][j]);
System.out.println("");
}
System.out.println("\nOperation ON Matrices \n1.Addition \n");
int sum [][] = new int [3][3];
for(i=0;i< 3;i++){
for(j=0;j< 3;j++){
sum[i][j] = mat1[i][j] + mat2[i][j];
System.out.print("\t" + sum[i][j]);
}
System.out.println("");
}
System.out.println("2.Subtraction\n");
int diff[][] = new int[3][3];
for(i=0;i< 3;i++){
for(j=0;j< 3;j++){
diff [i][j] = mat1[i][j] - mat2[i][j];
System.out.print("\t"+ diff[i][j]);
}
System.out.println("");
Kanishk Chouhan
(0827CS201112)
Name of Student: Kanishk Chouhan Class: BE-II YEAR
Enrollment No: 0827CS201112 Batch:2020-24
Date of Experiment Date of Submission Submitted on:
Remarks by faculty: Grade:
Signature of student: Signature of Faculty:
}
System.out.println("3. Transpose Of A\n");
int trans[][] = new int[3][3];
for(i=0;i< 3;i++){
for(j=0;j< 3;j++){
trans [i][j] = mat1[j][i];
System.out.print("\t"+ trans[i][j]);
}
System.out.println("");
}
System.out.println("4.Multiplication\n");
int prod[][] = new int[3][3];
for(i=0;i< 3;i++){
for(j=0;j< 3;j++){
prod[i][j] = 0;
for(k=0;k< 3;k++){
prod[i][j] = prod[i][j]+mat1[i][k]*mat2[k][j];
}
System.out.print("\t"+ prod[i][j]);
}
System.out.println("");
}
}
}
Output:
java -cp /tmp/RmpNdZjclM Matrix
Kanishk Chouhan
0827CS201112
Matrix A:
1 2 3
4 5 6
7 8 9
Matrix B:
Kanishk Chouhan
(0827CS201112)
Name of Student: Kanishk Chouhan Class: BE-II YEAR
Enrollment No: 0827CS201112 Batch:2020-24
Date of Experiment Date of Submission Submitted on:
Remarks by faculty: Grade:
Signature of student: Signature of Faculty:
10 11 12
13 14 15
16 17 18
Operation ON Matrices
1.Addition
11 13 15
17 19 21
23 25 27
2.Subtraction
-9 -9 -9
-9 -9 -9
-9 -9 -9
3. Transpose Of A
1 4 7
2 5 8
3 6 9
4.Multiplication
84 90 96
201 216 231
318 342 366
Kanishk Chouhan
(0827CS201112)
Name of Student: Kanishk Chouhan Class: BE-II YEAR
Enrollment No: 0827CS201112 Batch:2020-24
Date of Experiment Date of Submission Submitted on:
Remarks by faculty: Grade:
Signature of student: Signature of Faculty:
}
class Circle extends Shape{
Circle(double radius){
length=radius;// initialises inherited length
}
public double area(){// overrides area() of Shape
return PI*length*length;// PI & length inherited from Shape
}
}
class PolyTest{
public static void main(String[] args){
System.out.println("Kanishk Chouhan");
System.out.println("0827CS201112");
Shape sh;// no object instance just variable declaration
Square sq = new Square(10.0);// sq is a Square object reference
Circle circ = new Circle(10.0);// circ is a Circle object reference
sh=sq;// sh dynamically bound to the Square object referenced by sq
System.out.println("Area of Square = " + sh.area());
sh=circ; // sh dynamically bound to the Circle object referenced by circ
System.out.println("Area of circle = " + sh.area());
}
}
Output:
Kanishk Chouhan
(0827CS201112)
Name of Student: Kanishk Chouhan Class: BE-II YEAR
Enrollment No: 0827CS201112 Batch:2020-24
Date of Experiment Date of Submission Submitted on:
Remarks by faculty: Grade:
Signature of student: Signature of Faculty:
Output:
Kanishk Chouhan
(0827CS201112)
Name of Student: Kanishk Chouhan Class: BE-II YEAR
Enrollment No: 0827CS201112 Batch:2020-24
Date of Experiment Date of Submission Submitted on:
Remarks by faculty: Grade:
Signature of student: Signature of Faculty:
fact = fact*i;
}
return fact;
}
public static void main(String args[]){
int n, r;
Scanner scanner = new Scanner(System.in);
System.out.println("Kanishk Chouhan");
System.out.println("0827CS201112");
System.out.println("Enter Value of n : ");
n = scanner.nextInt();
System.out.println("Enter Value of r : ");
r = scanner.nextInt();
System.out.println("NCR is " +(fact(n)/(fact(n-r)*fact(r))));
System.out.println("\nNPR is " +(fact(n)/(fact(n-r))));
}
}
Output:
Kanishk Chouhan
(0827CS201112)
Name of Student: Kanishk Chouhan Class: BE-II YEAR
Enrollment No: 0827CS201112 Batch:2020-24
Date of Experiment Date of Submission Submitted on:
Remarks by faculty: Grade:
Signature of student: Signature of Faculty:
15. Write a program to show the difference between Equal function [.equal()] and
Compare Operator [==].
public class Equal {
public static void main(String[] args){
System.out.println("Kanishk Chouhan");
System.out.println("0827CS201112");
String s1 = "HELLO";
String s2 = "HELLO";
String s3 = new String("HELLO");
System.out.println(s1 == s2); // true
System.out.println(s1 == s3); // false
System.out.println(s1.equals(s2)); // true
System.out.println(s1.equals(s3)); // true
}
Kanishk Chouhan
(0827CS201112)
Name of Student: Kanishk Chouhan Class: BE-II YEAR
Enrollment No: 0827CS201112 Batch:2020-24
Date of Experiment Date of Submission Submitted on:
Remarks by faculty: Grade:
Signature of student: Signature of Faculty:
}
Output:
Kanishk Chouhan
(0827CS201112)