Professional Documents
Culture Documents
18BCE2196 19thfeb
18BCE2196 19thfeb
Saksham Goyal
Q1
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number of elements you want to store: ");
n=sc.nextInt();
int[] array = new int[10];
System.out.println("Enter the elements of the array: ");
for(int i=0; i<n; i++)
{
array[i]=sc.nextInt();
}
System.out.println("Array elements are: ");
for (int i=0; i<n; i++)
{
System.out.println(array[i]);
}
}
}
Q2
}
}
Q3
}
}
}
public static void main(String[] args) {
int arr[] ={3,60,35,2,45,320,5};
Q4
class Main
{
static int removeDuplicates(int arr[], int n)
{
if (n==0 || n==1)
return n;
int j = 0;
for (int i=0; i<n-1; i++)
if (arr[i] != arr[i+1])
temp[j++] = arr[i];
temp[j++] = arr[n-1];
return j;
}
public static void main (String[] args)
{
int arr[] = {1, 2, 2, 3, 4, 4, 4, 5, 5};
int n = arr.length;
n = removeDuplicates(arr, n);
Q5
Q6
int a[][] = {
{1, 0, 0},
{0, 1, 0},
{0, 0, 1}
};
rows = a.length;
cols = a[0].length;
if(rows != cols){
System.out.println("Matrix should be a square matrix");
}
else {
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
if(i == j && a[i][j] != 1){
flag = false;
break;
}
if(i != j && a[i][j] != 0){
flag = false;
break;
}
}
}
if(flag)
System.out.println("Given matrix is an identity matrix");
else
System.out.println("Given matrix is not an identity matrix");
}
}
}
Q7
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
transpose[i][j]=original[j][i];
}
}