Skip to content

Commit 642a2e4

Browse files
Java Code
1 parent 58f695e commit 642a2e4

File tree

3 files changed

+114
-22
lines changed

3 files changed

+114
-22
lines changed

DataHiding.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
public class DataHiding {
2+
3+
private int no;
4+
private String name;
5+
private String Address;
6+
7+
public int getno(){
8+
return no;
9+
10+
}
11+
public void setno(int n)
12+
{
13+
// no=n;
14+
this.no=n;
15+
}
16+
public DataHiding(String naam,String add)
17+
18+
{
19+
this.name=naam;
20+
this.Address=add;
21+
}
22+
public void Display()
23+
{
24+
System.out.println("Number="+no+"\n"+"Name="+name+"\n"+"Address="+Address);
25+
}
26+
27+
public class nestedClass //Inner Class Or Nested Class
28+
{
29+
private String Country;
30+
31+
32+
public void func(String Country)
33+
{
34+
System.out.println("COuntry="+Country);
35+
}
36+
}
37+
38+
39+
40+
}

Matrix.java

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,58 @@
11
import java.util.Scanner;
22

33
public class Matrix {
4-
public static void main(String[] args) {
5-
Scanner sc = new Scanner(System.in);
6-
System.out.println("enter the number of ROWS=");
7-
int rows = sc.nextInt();
84

9-
System.out.println("enter the number of columns");
10-
int cols = sc.nextInt();
5+
public static void main(String[] args) {
6+
int [][]matrix1=new int[3][3];
7+
int [][]matrix2=new int[3][3];
8+
int [][]addition=new int[3][3];
9+
int i,j;
10+
Scanner sc =new Scanner(System.in);
11+
System.out.println("Enter the elements=");
12+
for (i=0;i<matrix1.length;i++)
13+
{
14+
for(j=0;j<matrix1[i].length;j++)
15+
{
16+
matrix1[i][j]=sc.nextInt();
17+
}
18+
}
19+
System.out.println("Matrix1=");
20+
for (i=0;i<matrix1.length;i++)
21+
{
22+
for(j=0;j<matrix1[i].length;j++)
23+
{
24+
System.out.print(matrix1[i][j]+" ");
25+
}
26+
System.out.println();
27+
}
28+
System.out.println("Enter the element of matrix 2=");
29+
for (i=0;i<matrix2.length;i++)
30+
{
31+
for(j=0;j<matrix2[i].length;j++)
32+
{
33+
matrix2[i][j]=sc.nextInt();
34+
}
35+
}
36+
System.out.println("Matrix2=");
37+
for (i=0;i<matrix1.length;i++)
38+
{
39+
for(j=0;j<matrix1[i].length;j++)
40+
{
41+
System.out.print(matrix2[i][j]+" ");
42+
}
43+
System.out.println();
44+
}
1145

12-
int number[][] = new int[rows][cols];
13-
14-
System.out.println("enter the inputs");
15-
for (int i = 0; i < rows; i++) {
16-
for (int j = 0; j < cols; j++) {
17-
number[i][j] = sc.nextInt();
18-
}
19-
}
20-
System.out.println("output");
21-
for (int i = 0; i < rows; i++) {
22-
for (int j = 0; j < cols; j++) {
23-
System.out.println(number[i][j] + " ");
24-
}
25-
System.out.println();
46+
System.out.println("Matrix Addition =");
47+
for (i=0;i<matrix1.length;i++)
48+
{
49+
for(j=0;j<matrix1[i].length;j++)
50+
{
51+
addition[i][j]=matrix1[i][j]+matrix2[i][j];
52+
System.out.print(addition[i][j] +" ");
53+
}
54+
System.out.println();
55+
}
2656
}
27-
}
28-
57+
2958
}

StudentMain.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.Date;
2+
import java.util.Scanner;
3+
4+
//import DataHiding.nestedClass;
5+
6+
public class StudentMain {
7+
public static void main(String[] args)
8+
{
9+
10+
11+
12+
DataHiding dhobj=new DataHiding("Saud","Chiplun");
13+
dhobj.setno(5);
14+
dhobj.Display();
15+
System.out.println();
16+
DataHiding.nestedClass innerObj=dhobj.new nestedClass();
17+
innerObj.func("India");
18+
19+
20+
21+
}
22+
23+
}

0 commit comments

Comments
 (0)