Isc Project Computer
Isc Project Computer
Write a program to declare a square matrix A[ ][ ] of order ‘n’. Allow the user to input positive
integers into this matrix. Perform the following tasks on the matrix:
(i) Output the original matrix.
(ii) Find the SADDLE POINT for the matrix. If the matrix has no saddle point,
[Note: A saddle point is an element of the matrix such that it is the minimum element for the
row to which it belongs and the maximum element for the column to which it belongs. Saddle
point for a given matrix is always unique.]
Example: In the Matrix
456
789
513
ALGORITHM
Step 1 - Start
Step 2 –Take a Square matrix a[][] of order n
Step 3 - Accept variables r and c as number of rows and columns
Step 4 – Take the elements in the array
Step 5 – Find the minimum of a row and return the index position
Step 6 - Display the saddle point
Step 7 - Create a main function
Step 8 – Create an object and calling the parent class method
Step 9 – Stop
VARIABLE DESCRIPTION
Variable Datatype Description
a[][] int To store the array elements
r int To enter the number of rows
c int To store the number of columns
a[][] int Array to store the elements
min int To store the minimum value
max int To store the maximum value
p int To store loop variable (i)
i int Loop variable
j int Loop variable
mp int To store the value of min.
OUTPUT
QUESTION
WRITE A PROGRAM IN Java to fill a square matrix of size “n*n” in a circular fashion(clockwise) with
natural numbers from 1 to n*n, taking ‘n’ as input.
For example : if n=4, then n*n=16. Hence the array will be filled as given below.
ALGORITHM
Step 1 - Start
Step 2 - Taking a square matrix a[][] of size n
Step 3 - Initialize value to be filled in matrix
Step 4 - accepting k , m , l and n
Step 5 - Print the first row from the remaining rows
Step 6 - Print the last column from the remaining column
Step 7 - Print the first column from the remaining columns
Step 8 - Driver program to test above function
Step 9 - Stop
Program
import java.util.*;
public class Spiral
{
void spiralFill(int m, int n, int a[][])
{
// Initialize value to be filled in matrix
int val = 1;
}
}
VARIABLE DESCRIPTION
Variable Data Type Description
val int To initialize value to be filled in
the matrix.
k int Starting row index
m int Ending row index
n int Ending column index
I int Starting column index
a[][] int To store the array elements
i int As loop variable
OUTPUT
Question:
A class Collection contains an array of 100 integers. Using the following class description, create an array
with common elements from two integer arrays. The members of the class are given below:
Class name: Collection
Data members/ Instance variables:
arr[] : integer array
len : length of array
Member functions:
Collection() : default constructor
Collection(int) : parameterized constructor to assign the length of the array.
void inparr() : to accept the array elements.
Collection common(Collection) : returns a Collection containing the common elements of current
Collection object and the Collection object passed as a parameter.
void arrange() : sort the array element of the object containing common elements in ascending order
using any sorting technique.
void display() : displays the array element.
Specify the class Collection giving the details of the constructors, void inparr() and void arrange(),
Collection common(Collection). You need to write the main().
ALGORITHM
PROGRAM
import java.util.*;
public class Collection
{
Scanner sc=new Scanner(System.in);
int arr[]=new int[100];
int len;
public Collection()
{
len=0;
for(int i=0;i<100;i++)
arr[i]=0;
}
public Collection(int l)
{
len=l;
for(int i=0;i<len;i++)
arr[i]=0;
}
}
}
public static void main()
{
Collection c1=new Collection(5);
Collection c2=new Collection(4);
Collection c3=new Collection(4);
System.out.println("First array:");
c1.inpar();
System.out.println("Second array:");
c2.inpar();
c3=c1.common(c2);
System.out.println("\nCommon elelments:");
c3.display();
System.out.println("\nCommon elelments in sorted order:");
c3.arrange();
c3.display();
}
}
QUESTION
A class Distance is designed to calculate the sum of two distances. The description of the
class is as follows:
Class name: Distance
Data members/ instance variables:
M :to store the distance in meters.
N :to store the distance in centimeter
Member functions/methods:
Distance( double X, double Y) : parameterized constructor to initialize the X to M and Y to N.
void display( ) : to print the distance in the given format 12km 56m.
Distance Add_Dis( Distance a, Distance b) : to add the distances passed as object and return the
result.
Specify the class Distance with the details of the data members and member functions. Also write
the main( ) and create the object to call the methods accordingly to fulfil the above task.
ALGORITHM
Step 1 - Start
Step 2 - Accept the distances as kilometer and meter
Step 3 - Assign kilometer into x and meter in y
Step 4 - Take input as distance a and b
Step 5 - Now calculate the distance.
Step 6 - Check conditions of dN
Step 7- Enter distance
Step 8 - Calculate d1,d2,d3
Step 9 - Print d3 and sum distance
Step 10 - Stop
PROGRAM
import java.util.*;
public class Distance
{
double M,N;
public Distance(double x,double y)
{
M=x;
N=y;
}
public void display()
{
System.out.println(M+"km"+" "+N+"m");
}
public Distance Add_Dis(Distance a,Distance b)
{
Distance d=new Distance(0,0);
d.M=a.M+b.M;
d.N=a.N+b.N;
if(d.N>=1000)
{
d.M+=1;
d.N-=1000;
}
return d;
}
public static void main()
{
Scanner sc = new Scanner(System.in);
double k,m,k1,m1;
System.out.println("Enter first distance");
k=sc.nextDouble();
m=sc.nextDouble();
System.out.println("Enter 2nd distance:");
k1=sc.nextDouble();
m1=sc.nextDouble();
Distance d1=new Distance(k,m);
Distance d2=new Distance(k1,m1);
Distance d3=new Distance(0,0);
d3=d1.Add_Dis(d1,d2);
System.out.println("The sum distance:");
d3.display();
}
}
VARIABLE DESCRIPTION
Variable Data Type Purpose
x double To input the parameterized
constructor to initialize the
kilometer to x
y double To input the parameterized
constructor to initialize the
meter to n
M double To store the distance in
kilometers.
N double To store the distance in meters.
km double Distance M is taken as km.
m double Distance N is taken as m.
a distance Parameter variable
b distance Parameter variable
d distance Parameter variable
k double To store 1st distance in km
m double To store 1st distance in m
k1 double To store 2st distance in km
m1 double To store 2st distance in m
d1 distance To display distance 1
d2 distance To display distance 2
d3 distance To display distance 3