0% found this document useful (0 votes)
5 views46 pages

Java Programs for Array Operations

The document contains multiple Java classes, each implementing a different functionality related to array manipulation and user input. These functionalities include calculating sums, finding averages, identifying prime numbers, and rearranging elements based on specific conditions. Each class contains a main method that prompts the user for input and processes the data accordingly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views46 pages

Java Programs for Array Operations

The document contains multiple Java classes, each implementing a different functionality related to array manipulation and user input. These functionalities include calculating sums, finding averages, identifying prime numbers, and rearranging elements based on specific conditions. Each class contains a main method that prompts the user for input and processes the data accordingly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

*;

public class Q1

public static void main(){

Scanner sc=new Scanner([Link]);

int a[]=new int[10], sum=0;

[Link]("Enter the Numbers");

for(int i=0;i<10;i++){

a[i]=[Link]();

sum+=a[i];

[Link]("The Sum:"+sum);

import [Link].*;

public class Q2

public static void main(){

Scanner sc=new Scanner([Link]);

int a[]=new int[10], even=0, odd=0;

[Link]("Enter the Numbers");

for(int i=0;i<10;i++){

a[i]=[Link]();

if(a[i]%2==0) {

even+=a[i];

}else{

odd+=a[i];

}
[Link]("The Even Sum:"+even);

[Link]("The Odd Sum:"+odd);

import [Link].*;

public class Q3

public static void main(){

Scanner sc=new Scanner([Link]);

int a[]=new int[10], sum=0, avg;

[Link]("Enter the Numbers");

for(int i=0;i<10;i++){

a[i]=[Link]();

sum+=a[i];

avg=sum/10;

[Link]("The Numbers Below Average are:");

for(int i=0;i<10;i++){

if(a[i]<avg) {

[Link](a[i]);

import [Link].*;

public class Q4

{
public static void main(){

Scanner sc=new Scanner([Link]);

int a[]=new int[10], sum=0, counter=0;

[Link]("Enter the Numbers");

for(int i=0;i<10;i++){

a[i]=[Link]();

for(int j=1;j<=a[i];j++) {

if(a[i]%j==0) {

counter++;

if(counter==2){

sum+=a[i];

counter=0;

[Link]("The Sum of Prime Numbers is:"+sum);

import [Link].*;

public class Q5

public static void main(){

Scanner sc=new Scanner([Link]);

int a[]=new int[10], c=0, test;

boolean flag=true;

[Link]("Enter the Numbers");

for(int i=0;i<10;i++){

a[i]=[Link]();

test=a[i];
while(test>0){

c++;

test/=10;

if(c!=3){

flag=false;

c=0;

if(flag) {

[Link]("all the Numbers are 3-Digit");

}else{

[Link]("all the Numbers are not 3-Digit");

import [Link].*;

public class Q6

public static void main(){

Scanner sc=new Scanner([Link]);

int a[]=new int[10];

boolean flag=true;

[Link]("Enter the Numbers");

int first=[Link]();

for(int i=0;i<9;i++){

a[i]=[Link]();

if(a[i]!=first){

flag=false;

}
}

if(flag) {

[Link]("all the Numbers are Same");

}else{

[Link]("all the Numbers are not Same");

import [Link].*;

public class Q7

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[]=new int[10];

boolean flag=true;

[Link]("Enter the Numbers:");

arr[0]=[Link]();

for(int i=1;i<10;i++){

arr[i]=[Link]();

if(arr[i-1]>arr[i]){

flag=false;

if(!flag) {

[Link]("The Number are not in Ascending Order");

}else{

[Link]("The Numbers are in Ascending Order");

}
import [Link].*;

public class Q8

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[]=new int[10], largest=0, smallest=0, larloc=0, smallloc=0;

[Link]("Enter the Numbers:");

largest=[Link]();

smallest=largest;

for(int i=1;i<10;i++){

arr[i]=[Link]();

if(arr[i]>largest) {

largest=arr[i];

larloc=i;

else if(arr[i]<smallest){

smallest=arr[i];

smallloc=i;

[Link]("Largest:"+largest+" Position:"+larloc);

[Link]("Smallest:"+smallest+" Position:"+smallloc);

import [Link].*;

public class Q9

{
public static void main(){

Scanner sc=new Scanner([Link]);

int arr[]=new int[10], largest=0, smallest=0, larloc=0, smallloc=0;

[Link]("Enter the Numbers:");

largest=[Link]();

smallest=largest;

for(int i=1;i<10;i++){

arr[i]=[Link]();

if(arr[i]>largest) {

largest=arr[i];

larloc=i;

} else if(arr[i]<smallest){

smallest=arr[i];

smallloc=i;

arr[larloc]=smallest;

arr[smallloc]=largest;

for(int i=0;i<10;i++) {

[Link](arr[i]);

import [Link].*;

public class Q10

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[]=new int[10],counter=0;

[Link]("Enter the Numbers:");


for(int i=0;i<10;i++){

arr[i]=[Link]();

for(int j=1;j<=arr[i];j++){

if(arr[i]%j==0){

counter++;

if(counter==2){

arr[i]=0;

counter=0;

for(int i=0;i<10;i++){

[Link](arr[i]);

import [Link].*;

public class Q11

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[]=new int[10], lar, lar2=0;

[Link]("Enter the Numbers:");

lar=[Link]();

for(int i=1;i<10;i++){

arr[i]=[Link]();

if(lar>arr[i] && arr[i]>lar2){

lar2=arr[i];

}
}

[Link]("Second Largest Number:"+lar2);

import [Link].*;

public class Q12

public static void main(){

Scanner sc=new Scanner([Link]);

[Link]("Enter the Numbers:");

int arr[]=new int[10], arr2[]=new int[10];

for(int i=0;i<10;i++){

arr[i]=[Link]();

for(int i=0,j=9;i<10;i++,j--){

arr2[j]=arr[i];

[Link]("Old one:");

for(int a:arr){

[Link](a+" ");

[Link]("\nNew One:");

for(int a:arr2){

[Link](a+" ");

import [Link].*;
public class Q13

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[]=new int[10];

[Link]("Enter the Numbers:");

for(int i=0;i<10;i++){

arr[i]=[Link]();

int fir=arr[0];

for(int i=0;i<9;i++){

arr[i]=arr[i+1];

arr[9]=fir;

for(int a:arr){

[Link](a+" ");

import [Link].*;

public class Q14

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[]=new int[10];

[Link]("Enter the Numbers:");

for(int i=0;i<10;i++){

arr[i]=[Link]();

[Link]("Enter the Number:");


int num=[Link]();

[Link]("Enter the Position to be Placed:");

int pos=[Link]();

for (int i = 9; i > pos; i--) {

arr[i] = arr[i - 1];

arr[pos]=num;

for(int a:arr){

[Link](a+" ");

import [Link].*;

public class Q15

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[]=new int[10];

int result[]=new int[10];

int index=0;

[Link]("Enter 10 positive or negative numbers (no 0):");

for(int i=0;i<10;i++){

arr[i]=[Link]();

for(int i=0;i<10;i++){

if(arr[i]>0){

result[index]=arr[i];

index++;

}
for(int i=0;i<10;i++){

if(arr[i]<0){

result[index]=arr[i];

index++;

[Link]("Array after shifting positives to front and negatives to end:");

for(int i=0;i<10;i++){

[Link](result[i]+" ");

import [Link].*;

public class Q16

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[]=new int[10];

int result[]=new int[10];

int index=0;

[Link]("Enter 10 positive or negative numbers (no 0):");

for(int i=0;i<10;i++){

arr[i]=[Link]();

for(int i=0;i<10;i++){

if(arr[i]%2==0){

result[index]=arr[i];

index++;

}
for(int i=0;i<10;i++){

if(arr[i]%2==1){

result[index]=arr[i];

index++;

[Link]("Array after shifting:");

for(int i=0;i<10;i++){

[Link](result[i]+" ");

import [Link].*;

public class Q17

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[]=new int[10];

[Link]("Enter the Numbers:");

for(int i=0;i<10;i++){

arr[i]=[Link]();

[Link]("Frequencies:");

for(int i=0;i<10;i++){

boolean alreadyCounted = false;

for(int k=0;k<i;k++){

if(arr[k]==arr[i]){

alreadyCounted = true;

break;

}
}

if(!alreadyCounted){

int counter = 0;

for(int j=0;j<10;j++){

if(arr[j]==arr[i]){

counter++;

[Link]("Number: " + arr[i] + " Frequency: " + counter);

import [Link].*;

public class Q18

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[]=new int[10], counter=0,max=0;

[Link]("Enter the Numbers:");

for(int i=0;i<10;i++){

arr[i]=[Link]();

for(int i=1;i<10;i++){

for(int j=1;j<10;j++){

if(arr[i]==arr[j]){

counter++;

if(counter>max) {
max=arr[i];

counter=0;

[Link]("The Number with Highest Frquency is:"+max);

import [Link].*;

public class Q19

public static void main(){

Scanner sc = new Scanner([Link]);

int arr[] = new int[10];

int index = 0, in = 0;

[Link]("Enter 10 positive or negative numbers (no 0):");

for(int i=0;i<10;i++){

arr[i] = [Link]();

for(int i=0;i<10;i++){

if(arr[i]%2==0){

index++;

int result[] = new int[index];

for(int i=0;i<10;i++){

if(arr[i]%2==0){

result[in] = arr[i];

in++;

}
[Link]("Array after shifting :");

for(int i=0;i<[Link];i++){

[Link](result[i]+" ");

import [Link].*;

public class Q20 {

public static void main() {

Scanner sc = new Scanner([Link]);

int arr[] = new int[10], counter, main = 0;

[Link]("Enter the Numbers:");

for (int i = 0; i < 10; i++) {

arr[i] = [Link]();

for (int i = 0; i < 10; i++) {

counter = 0;

for (int j = 0; j < 10; j++) {

if (arr[j] == arr[i]) {

counter++;

if (counter == 1) {

main++;

int result[] = new int[main];

int idx = 0;

for (int i = 0; i < 10; i++) {

counter = 0;
for (int j = 0; j < 10; j++) {

if (arr[j] == arr[i]) {

counter++;

if (counter == 1) {

result[idx] = arr[i];

idx++;

[Link]("Unique numbers are:");

for (int a : result) {

[Link](a + " ");

import [Link].*;

public class Q21 {

public static void main() {

Scanner sc = new Scanner([Link]);

int arr[] = new int[10];

[Link]("Enter the Numbers:");

for (int i = 0; i < 10; i++) {

arr[i] = [Link]();

[Link]("Numbers printed only once:");

for (int i = 0; i < 10; i++) {

boolean alreadyPrinted = false;

for (int j = 0; j < i; j++) {

if (arr[j] == arr[i]) {
alreadyPrinted = true;

break;

if (!alreadyPrinted) {

[Link](arr[i] + " ");

import [Link].*;

public class Q22 {

public static void main() {

Scanner sc = new Scanner([Link]);

int arr[] = new int[10];

int index = 0, even = 0, odd = 0, index1 = 0;

[Link]("Enter 10 positive or negative numbers (no 0):");

for (int i = 0; i < 10; i++) {

arr[i] = [Link]();

for (int i = 0; i < 10; i++) {

if (arr[i] % 2 == 0) {

even++;

for (int i = 0; i < 10; i++) {

if (arr[i] % 2 == 1) {

odd++;

}
int evenarr[] = new int[even];

int oddarr[] = new int[odd];

for (int i = 0; i < 10; i++) {

if (arr[i] % 2 == 0) {

evenarr[index] = arr[i];

index++;

for (int i = 0; i < 10; i++) {

if (arr[i] % 2 == 1) {

oddarr[index1] = arr[i];

index1++;

[Link]("Array before Change:");

for(int a:arr){

[Link](a + " ");

[Link]();

[Link]("Even No. Array");

for(int a:evenarr){

[Link](a + " ");

[Link]();

[Link]("Odd No. Array");

for(int a:oddarr){

[Link](a + " ");

[Link]();

}
import [Link].*;

public class Q23 {

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[][]=new int[5][5];

[Link]("Enter the Values:");

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

[Link]("Enter value for row " + (i+1) + ", column " + (j+1) + ": ");

arr[i][j] = [Link]();

int largest=arr[0][0], smallest=arr[0][0];

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

if(arr[i][j]>largest){

largest=arr[i][j];

else if(arr[i][j]<smallest){

smallest=arr[i][j];

[Link]("Largest:"+largest);

[Link]("Smallest:"+smallest);

import [Link].*;

public class Q24 {


public static void main(){

Scanner sc=new Scanner([Link]);

int arr[][]=new int[5][5], lposr=0, lposc=0, sposr=0, sposc=0;

[Link]("Enter the Values:");

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

[Link]("Enter value for row " + (i+1) + ", column " + (j+1) + ": ");

arr[i][j] = [Link]();

int largest=arr[0][0], smallest=arr[0][0];

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

if(arr[i][j]>largest){

largest=arr[i][j];

lposr=i;

lposc=j;

else if(arr[i][j]<smallest){

smallest=arr[i][j];

sposr=i;

sposc=j;

arr[lposr][lposc]=smallest;

arr[sposr][sposc]=largest;

[Link]("------");

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

[Link](arr[i][j]+"\t");

[Link]();
}

import [Link].*;

public class Q25 {

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[][]=new int[5][5];

int sum[]=new int[5];

[Link]("Enter the Values:");

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

[Link]("Enter value for row " + (i+1) + ", column " + (j+1) + ": ");

arr[i][j] = [Link]();

[Link]("-------------------");

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

sum[i]+=arr[i][j];

[Link]("The sum of the Row "+(i+1)+" is "+sum[i]);

import [Link].*;

public class Q26 {


public static void main(){

Scanner sc=new Scanner([Link]);

int arr[][]=new int[5][5];

int sum[]=new int[5];

[Link]("Enter the Values:");

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

[Link]("Enter value for row " + (i+1) + ", column " + (j+1) + ": ");

arr[i][j] = [Link]();

[Link]("-------------------");

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

sum[i]+=arr[j][i];

[Link]("The sum of the column "+(i+1)+" is "+sum[i]);

import [Link].*;

public class Q27 {

public static void main() {

Scanner sc = new Scanner([Link]);

int arr[][] = new int[5][5];

[Link]("Enter the values for the 5x5 array:");

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

[Link]("Enter value for row " + (i+1) + ", column " + (j+1) + ": ");

arr[i][j] = [Link]();
}

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 4; j++) {

for (int k = 0; k < 4-j; k++) {

if (arr[i][k] > arr[i][k+1]) {

int temp = arr[i][k];

arr[i][k] = arr[i][k+1];

arr[i][k+1] = temp;

[Link]("\nArray after sorting each row in ascending order:");

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

[Link](arr[i][j] + "\t");

[Link]();

import [Link];

public class Q28 {

public static void main() {

Scanner sc = new Scanner([Link]);

int[][] arr = new int[5][5];

[Link]("Enter the values for the 5x5 array:");

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {


[Link]("Enter value for row " + (i + 1) + ", column " + (j + 1) + ": ");

arr[i][j] = [Link]();

for (int col = 0; col < 5; col++) {

for (int i = 0; i < 4; i++) {

for (int j = i + 1; j < 5; j++) {

if (arr[i][col] < arr[j][col]) {

int temp = arr[i][col];

arr[i][col] = arr[j][col];

arr[j][col] = temp;

[Link]("\nArray after sorting each column in descending order:");

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

[Link](arr[i][j] + "\t");

[Link]();

import [Link].*;

public class Q29

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[][]=new int[5][5],counter=0;


[Link]("Enter the values for the 5x5 array:");

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

[Link]("Enter value for row " + (i + 1) + ", column " + (j + 1) + ": ");

arr[i][j] = [Link]();

[Link]("------");

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

[Link](arr[i][j]+" ");

[Link]();

[Link]("------");

boolean[][] visited = new boolean[5][5];

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

if(!visited[i][j]){

counter=0;

for(int k=0;k<5;k++){

for(int l=0;l<5;l++){

if(arr[i][j]==arr[k][l]){

counter++;

visited[k][l]=true;

[Link]("The frequency of the Number "+arr[i][j]+" is "+counter);

}
}

import [Link].*;

public class Q30

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[][]=new int[5][5],counter=0;

[Link]("Enter the values for the 5x5 array:");

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

[Link]("Enter value for row " + (i + 1) + ", column " + (j + 1) + ": ");

arr[i][j] = [Link]();

[Link]("-------------------");

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

[Link](arr[i][j]+" ");

[Link]();

[Link]("------");

[Link]("Enter the Number to be searched:");

int num=[Link]();

boolean check=false;

int locr=0,locc=0;

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

if(arr[i][j]==num){

check=true;
locr=i+1;

locc=j+1;

if(!check) {

[Link]("The Number is not present in the Matric");

}else{

[Link]("The Number is present at the "+locr+" row and "+locc+" column");

import [Link].*;

public class Q30

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[][]=new int[5][5],counter=0;

[Link]("Enter the values for the 5x5 array:");

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

[Link]("Enter value for row " + (i + 1) + ", column " + (j + 1) + ": ");

arr[i][j] = [Link]();

[Link]("-------------------");

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

[Link](arr[i][j]+" ");

}
[Link]();

[Link]("------");

[Link]("Enter the Number to be searched:");

int num=[Link]();

boolean check=false;

int locr=0,locc=0;

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

if(arr[i][j]==num){

check=true;

locr=i+1;

locc=j+1;

if(!check) {

[Link]("The Number is not present in the Matric");

}else{

[Link]("The Number is present at the "+locr+" row and "+locc+" column");

import [Link].*;

public class Q31

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[][]=new int[5][5], counter=0;

[Link]("Enter the values for the 5x5 array:");


for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

[Link]("Enter value for row " + (i + 1) + ", column " + (j + 1) + ": ");

arr[i][j] = [Link]();

[Link]("-------------------");

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

[Link](arr[i][j]+" ");

[Link]();

[Link]("------");

boolean flag=true;

boolean[][] diag = new boolean [5][5];

for(int i=0;i<5;i++){

if(arr[i][i]==1){

diag[i][i]=true;

}else{

flag=false;

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

if(diag[i][j]==false){

if(arr[i][j]==0){

diag[i][j]=true;

}else{

flag=false;

}
}

if(!flag) {

[Link]("It is not a Unit Matrix");

}else{

[Link]("It is a Unit Matrix");

import [Link].*;

public class Q32

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[][]=new int[5][5],counter=0;

[Link]("Enter the values for the 5x5 array:");

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

[Link]("Enter value for row " + (i + 1) + ", column " + (j + 1) + ": ");

arr[i][j] = [Link]();

[Link]("-------------------");

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

[Link](arr[i][j]+" ");

[Link]();

[Link]("----------");

boolean[][] diag = new boolean [5][5];


boolean flag=true;

for(int i=0;i<5;i++){

if(arr[i][i]!=0){

diag[i][i]=true;

}else{

flag=false;

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

if(diag[i][j]==false){

if(arr[i][j]==0){

diag[i][j]=true;

}else{

flag=false;

if(!flag) {

[Link]("It is not a Diagonal Matrix");

}else{

[Link]("It is a Diagonal Matrix");

import [Link].*;

public class Q33

public static void main(){


Scanner sc=new Scanner([Link]);

int arr[][]=new int[5][5],counter=0;

[Link]("Enter the values for the 5x5 array:");

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

[Link]("Enter value for row " + (i + 1) + ", column " + (j + 1) + ": ");

arr[i][j] = [Link]();

[Link]("------");

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

[Link](arr[i][j]+" ");

[Link]();

[Link]("------");

int tran[][]=new int[5][5];

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

tran[j][i]=arr[i][j];

[Link]("Transposed Matrix\n-------------------");

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

[Link](tran[i][j]+" ");

[Link]();

[Link]("----------");

}
import [Link].*;

public class Q34

public static void main() {

Scanner sc = new Scanner([Link]);

int arr[][] = new int[5][5], counter = 0;

[Link]("Enter the values for the 5x5 array:");

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

[Link]("Enter value for row " + (i + 1) + ", column " + (j + 1) + ": ");

arr[i][j] = [Link]();

[Link]("-------------------");

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

[Link](arr[i][j] + " ");

[Link]();

[Link]("-------------------");

int tran[][] = new int[5][5];

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

tran[j][i] = arr[i][j];

boolean flag = true;

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {


if (arr[i][j] != tran[i][j]) {

flag = false;

if (!flag) {

[Link]("It is not a Symetric Matrix");

} else {

[Link]("It is a Symetric Matrix");

import [Link].*;

public class Q35 {

public static void main() {

Scanner sc = new Scanner([Link]);

int n = 5;

int[][] arr = new int[n][n];

[Link]("Enter the values for the 5x5 array:");

for (int i = 0; i < n; i++) {

for (int j = 0; j < n; j++) {

[Link]("Enter value for row " + (i + 1) + ", column " + (j + 1) + ": ");

arr[i][j] = [Link]();

boolean zeroAbove = true;

for (int i = 0; i < n && zeroAbove; i++) {

for (int j = i + 1; j < n; j++) {

if (arr[i][j] != 0) {
zeroAbove = false;

break;

boolean nonZeroBelow = true;

for (int i = 1; i < n && nonZeroBelow; i++) {

for (int j = 0; j < i; j++) {

if (arr[i][j] == 0) {

nonZeroBelow = false;

break;

if (zeroAbove && nonZeroBelow) {

[Link]("The matrix is a lower triangular matrix with non-zero lower half.");

} else {

[Link]("The matrix does not satisfy the required conditions.");

import [Link].*;

public class Q36

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[][]=new int[3][3],arr2[][]=new int[3][3],sum[][]=new int[3][3];

[Link]("Enter the values for the First 3X3 array:");

for (int i = 0; i < 3; i++) {


for (int j = 0; j < 3; j++) {

[Link]("Enter value for row " + (i + 1) + ", column " + (j + 1) + ": ");

arr[i][j] = [Link]();

[Link]("Enter the values for the First 3X3 array:");

for (int i = 0; i < 3; i++) {

for (int j = 0; j < 3; j++) {

[Link]("Enter value for row " + (i + 1) + ", column " + (j + 1) + ": ");

arr2[i][j] = [Link]();

for(int i=0;i<3;i++){

for(int j=0;j<3;j++){

sum[i][j]=arr[i][j]+arr2[i][j];

[Link]("The Summed Matrix\n-------------------");

for(int i=0;i<3;i++){

for(int j=0;j<3;j++){

[Link](sum[i][j]+" ");

[Link]();

[Link]("--------------------");

}
import [Link].*;

public class Q37

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[][]=new int[5][5],counter=0;

[Link]("Enter the values for the 5x5 array:");

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

[Link]("Enter value for row " + (i + 1) + ", column " + (j + 1) + ": ");

arr[i][j] = [Link]();

[Link]("-------------------");

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

[Link](arr[i][j]+" ");

[Link]();

[Link]("-------------------");

boolean flag=false;

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

if(arr[i][j]!=0){

flag=true;

break;

if(!flag){
[Link]("The Matrix is a Null Matrix");

}else{

[Link]("The Matrix is not a Null Matrix");

import [Link].*;

public class Q38

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[][]=new int[5][5],counter=0;

[Link]("Enter the values for the 5x5 array:");

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5; j++) {

[Link]("Enter value for row " + (i + 1) + ", column " + (j + 1) + ": ");

arr[i][j] = [Link]();

[Link]("-------------------");

for(int i=0;i<5;i++){

for(int j=0;j<5;j++){

[Link](arr[i][j]+" ");

[Link]();

[Link]("-------------------");

boolean flag=false;
int checker=arr[0][0];

for(int i=1;i<5;i++){

if(arr[i][i]!=checker){

flag=true;

break;

if(!flag){

[Link]("The Matrix is a Scalar Matrix");

}else{

[Link]("The Matrix is not a Scalar Matrix");

import [Link].*;

class Q39 {

static void main() {

Scanner sc = new Scanner([Link]);

int roll[] = new int[50];

int marks[][] = new int[50][3]; // 2D array for marks of 3 subjects

float av[] = new float[50];

[Link]("Enter the roll number and marks of 3 subjects for 50 students:");

for (int i = 0; i < 50; i++) {

roll[i] = [Link]();

for (int j = 0; j < 3; j++) {

marks[i][j] = [Link]();
}

av[i] = (float)(marks[i][0] + marks[i][1] + marks[i][2]) / 3;

[Link]("Average marks obtained by each student:");

[Link]("Roll\tAverage");

for (int i = 0; i < 50; i++) {

[Link](roll[i] + "\t" + av[i]);

[Link]("Students with average marks above 80:");

[Link]("Roll\tAverage");

for (int i = 0; i < 50; i++) {

if (av[i] > 80) {

[Link](roll[i] + "\t" + av[i]);

[Link]("Students with average marks below 40:");

[Link]("Roll\tAverage");

for (int i = 0; i < 50; i++) {

if (av[i] < 40) {

[Link](roll[i] + "\t" + av[i]);

[Link]();

}
import [Link].*;

public class Q40

public static void main(){

Scanner sc=new Scanner([Link]);

[Link]("Enter the No of Students:");

int n=[Link]();

String name[]=new String[n];

int totalmarks[]=new int[n];

int dev[]=new int[n];

int sum=0,avg;

for(int i=0;i<n;i++){

[Link]("Enter the Name of "+(i+1)+" Student and their total marks:");

[Link]();

name[i]=[Link]();

totalmarks[i]=[Link]();

sum+=totalmarks[i];

avg=sum/n;

[Link]("Average is:"+avg);

for(int i=0;i<n;i++){

dev[i]=totalmarks[i]-avg;

[Link]("Deviation of the Student "+name[i]+" is "+dev[i]);

import [Link].*;

public class Q41

{
public static void main(){

Scanner sc=new Scanner([Link]);

int arr[]={2,5,7,10,15,20,29,30,46,50};

[Link]("Enter the Number to be Searched:");

int num=[Link]();

int first=0,last=[Link]-1,mid;

boolean flag=false;

for(int i=0;i<[Link]-1;i++){

mid=(first+last)/2;

if(num>arr[mid]){

first=mid+1;

}else if(num<arr[mid]){

last=mid-1;

}else{

[Link]("The Number is Found at the Index:"+mid);

flag=true;

break;

if(!flag){

[Link]("The Number is Not present");

import [Link].*;

public class Q42

public static void main(){

Scanner sc=new Scanner([Link]);


double arr[]=new double[20],product=1;

[Link]("Enter the Numbers:");

for(int i=0;i<20;i++){

arr[i]=[Link]();

product*=arr[i];

[Link]("The Product is:"+product);

[Link]("-------------------------------------");

for(double a:arr){

[Link](a*a);

import [Link].*;

public class Q43

public static void main(){

Scanner sc=new Scanner([Link]);

double arr[]=new double[20],product=1;

[Link]("Enter the Numbers:");

for(int i=0;i<20;i++){

arr[i]=[Link]();

[Link]("-------------------------------------");

[Link]("Enter the Number to be Searched:");

int num=[Link]();

boolean flag=false;

for(int i=0;i<10;i++){

if(arr[i]==num){
[Link]("The Number is found at "+i);

flag=true;

break;

if(!flag){

[Link]("The Number is Not present in the Array");

import [Link].*;

public class Q44

public static void main(){

Scanner sc=new Scanner([Link]);

int arr[]=new int[10],temp,counter=0,single=0,two=0;

[Link]("Enter the Numbers:");

for(int i=0;i<10;i++){

arr[i]=[Link]();

temp=arr[i];

while(temp>0){

temp/=10;

counter++;

if(counter==1){

single+=arr[i];

}else if(counter==2){

two+=arr[i];

}
counter=0;

temp=0;

[Link]("Sum of Single digit numbers:"+single);

[Link]("Sum of Two digit Numbers:"+two);

You might also like