Code Below:
import java.util.*;
class midpoint
{
int x,y;
midpoint()
{
x=0;
y=0;
}
void get()
{
Scanner s=new Scanner(System.in);
System.out.println("Enter the absicca and ordinate");
x=s.nextInt();
y=s.nextInt();
}
void calculate(midpoint A, midpoint B)
{
this.x=(A.x + B.x)/2;
this.y=(A.y + B.y)/2;
}
void show()
{
System.out.println("x="+x);
System.out.println("y="+y);
}
public static void main()
{
midpoint A = new midpoint();
midpoint B = new midpoint();
midpoint M = new midpoint();
System.out.println("Point A");
A.get();
System.out.println("Point B");
B.get();
M.calculate(A,B);
System.out.println("Mid Point co-ordinates");
M.show();
}
}
Code Below:
import java.util.*;
class addmatrix
{
int dda[][];
int row;
int col;
addmatrix(int v1, int v2)
{
row=v1;
col=v2;
dda=new int[row][col];
}
void input()
{
Scanner s=new Scanner(System.in);
System.out.println("Enter the elements of the array");
for (int i=0; i< row; i++)
{
for (int j=0; j< col; j++)
{
dda[i][j]=s.nextInt();
}
}
}
void add(addmatrix a, addmatrix b)
{
for (int i=0; i< row; i++)
{
for (int j=0; j< col; j++)
{
this.dda[i][j]=a.dda[i][j]+b.dda[i][j];
}
}
}
void display()
{
for (int i=0; i< row; i++)
{
for (int j=0; j< col; j++)
{
System.out.print(dda[i][j]+"\t");
}
System.out.println();
}
}
public static void main()
{
Scanner s=new Scanner(System.in);
System.out.println("Enter the rows and colums of the matrices");
int r=s.nextInt();
int c=s.nextInt();
addmatrix a= new addmatrix(r,c);
addmatrix b= new addmatrix(r,c);
addmatrix m= new addmatrix(r,c);
System.out.println("For Matrix A[][]");
a.input();
System.out.println("For Matrix B[][]");
b.input();
m.add(a,b);
System.out.println("For Matrix A[][]");
a.display();
System.out.println("For Matrix B[][]");
b.display();
System.out.println("Resultant Matrix C[][]");
m.display();
}
}