0% found this document useful (0 votes)
13 views

Final Array Assignment Solution 2024-25

The document contains multiple Java classes that implement various algorithms and functionalities, including sorting (Bubble Sort, Selection Sort), searching (Binary Search), and matrix operations. Each class demonstrates a specific task such as finding the maximum and minimum values, calculating sums, and checking properties of arrays. The document serves as a collection of coding exercises for educational purposes, showcasing different programming concepts.

Uploaded by

meetmulani571
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Final Array Assignment Solution 2024-25

The document contains multiple Java classes that implement various algorithms and functionalities, including sorting (Bubble Sort, Selection Sort), searching (Binary Search), and matrix operations. Each class demonstrates a specific task such as finding the maximum and minimum values, calculating sums, and checking properties of arrays. The document serves as a collection of coding exercises for educational purposes, showcasing different programming concepts.

Uploaded by

meetmulani571
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

1 Board Array Solution 2024-25

2024

class P2024
{
public static void main()
{
int x[] = {110061,110001,110029,110023,110055,110006,110019,110033};
int i,j,t;
int n = x.length;
int small,pos;
for(i = 0; i < n-1 ; i++)
{
small = x[i];
pos = i;
for(j = i + 1; j < n ; j++)
{
if(x[j] < small)
{
small = x[j];
pos = j;
}
}
t = x[i];
x[i] = x[pos];
x[pos] = t;
}
for(i = 0; i < n; i++)
{
System.out.println(x[i]);
}
}
}
2 Board Array Solution 2024-25

import java.util.*;
class P2024_B
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int x[][] = new int[4][4];
int r,c;
for(r = 0; r < 4; r++)
{
for(c = 0; c < 4; c++)
{
System.out.print("Enter no : ");
x[r][c] = sc.nextInt();
}
}
System.out.println("Printing the matrix ");
for(r = 0; r < 4; r++)
{
for(c = 0; c < 4; c++)
{
System.out.print(x[r][c] + "\t");
}
System.out.println();
}
int suml = 0, sumr = 0;
for(r = 0; r < 4; r++)
{
for(c = 0; c < 4; c++)
{
if(r == c)
suml = suml + x[r][c];
if(r+c == 3)
sumr = sumr + x[r][c];
}
}
if(suml == sumr)
System.out.println("It is a diagonal array");
else
System.out.println("It is not a diagonal array");
}
}
3 Board Array Solution 2024-25

2023

import java.util.*;
class Array8
{
public static void main()
{
Scanner sc = new Scanner(System.in);
double x[] = new double[20];
int i;
for(i=0;i<20;i++)
{
System.out.println("Enter number : ");
x[i] = sc.nextDouble();
}
System.out.print("Enter number to be searched : ");
double value = sc.nextDouble();
int pos = -1;
for(i=0;i<20;i++)
{
if(value == x[i])
{
pos = i;
break;
}
}
if(pos != -1)
System.out.println("Number found at position " + (pos+1));
else
System.out.println("Number Not Found ");
}
}
4 Board Array Solution 2024-25

import java.util.*;
class Array
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int x[] = new int[10];
int i;
for(i=0;i<10;i++)
{
System.out.println("Enter number : ");
x[i] = sc.nextInt();
}
int sum1=0,sum2=0;
for(i=0;i<10;i++)
{
if(x[i] >= 0 && x[i] <= 9)
sum1 = sum1+x[i];
else
if(x[i] >= 10 && x[i] <= 99)
sum2 = sum2+x[i];
}
System.out.println("Sum of one digit numbers " + sum1);
System.out.println("Sum of two digit numbers " + sum2);
}
}
5 Board Array Solution 2024-25

2022

import java.util.*;
class Binary
{
public static void main()
{
int x[] = {2,5,7,10,15,20,29,30,46,50};
Scanner sc = new Scanner(System.in);
System.out.print("Enter number to be searched : ");
int value = sc.nextInt();
int lb = 0,ub = x.length-1, mid, pos = -1;
while(lb <= ub)
{
mid = (lb+ub)/2;
if(value == x[mid])
{
pos = mid;
break;
}
else
if(value > x[mid])
lb = mid + 1;
else
ub = mid - 1;
}
if(pos != -1)
System.out.println("Number found at index " + pos );
else
System.out.println("Number Not Found ");
}
}
6 Board Array Solution 2024-25

import java.util.*;
class Arr2
{
public static void main()
{
Scanner sc = new Scanner(System.in);
char x[] = new char[10];
int i, j;
for(i = 0; i < 10; i++)
{
System.out.println("Enter a character ");
x[i] = sc.next().charAt(0);
}
char min = x[0], max = x[0];
for(i = 1; i < 10; i++)
{
if(x[i] < min)
min = x[i];
if(x[i] > max)
max = x[i];
}
System.out.println("Character with highest ASCII value = " + max);
System.out.println("Character with lowest ASCII value = " + min);
}
}
7 Board Array Solution 2024-25

import java.util.*;
class Array9
{
public static void main()
{
Scanner sc = new Scanner(System.in);
double x[] = new double[20];
int i;
for(i=0;i<20;i++)
{
System.out.println("Enter number : ");
x[i] = sc.nextDouble();
}
double sq, pro=1;

for(i=0;i<20;i++)
{
sq=x[i]*x[i];
System.out.println("Square of " + x[i] + " = " + sq);
pro = pro * x[i];
}
System.out.println("Product of all numbers " + pro);
}
}
8 Board Array Solution 2024-25

import java.util.*;
class Arr1
{
public static void main()
{
Scanner sc = new Scanner(System.in);
String x[] = new String[10];
int i, j;
for(i = 0; i < 10; i++)
{
System.out.println("Enter name ");
x[i] = sc.next();
}
for(i = 0; i < 10; i++)
{
char ch1 = x[i].charAt(0);
char ch2 = x[i].charAt(x[i].length()-1);
if((ch1 == 'A' || ch1 == 'a') && (ch2 == 'A' || ch1 == 'a'))
System.out.println(x[i]);
}
}
}
9 Board Array Solution 2024-25

2020

import java.util.*;
class Diagonal
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int x[][] = new int[3][3];
int r,c;
for(r = 0; r < 3; r++)
{
for(c = 0; c < 3; c++)
{
System.out.print("Enter no : ");
x[r][c] = sc.nextInt();
}
}
System.out.println("Printing the matrix ");
for(r = 0; r < 3; r++)
{
for(c = 0; c < 3; c++)
{
System.out.print(x[r][c] + "\t");
}
System.out.println();
}

int sum = 0;
for(r = 0; r < 3; r++)
{
for(c = 0; c < 3; c++)
{
if(r == c)
sum = sum + x[r][c];
}
}
System.out.println("Sum of left diagonal " + sum);
}
}
10 Board Array Solution 2024-25

import java.util.*;
class BinarySearch
{
public static void main()
{
int x[] = {31,36,45,50,60,75,86,90};
Scanner sc = new Scanner(System.in);
System.out.print("Enter number to be searched : ");
int value = sc.nextInt();
int lb = 0,ub = x.length-1, mid, pos = -1;
while(lb <= ub)
{
mid = (lb+ub)/2;
if(value == x[mid])
{
pos = mid;
break;
}
else
if(value > x[mid])
lb = mid + 1;
else
ub = mid - 1;
}
if(pos != -1)
System.out.println("Number found at index " + pos );
else
System.out.println("Number Not Found ");
}
}
11 Board Array Solution 2024-25

2019

import java.io.*;
class BubbleSort
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int x[]=new int[15];
int i,j,t;
for(i= 0 ;i < 15; i++)
{
System.out.print("Enter number : ");
x[i] = sc.nextInt();
}
for(i = 0; i < 14; i++)
{
for(j = 0; j < 14-i ; j++)
{
if(x[j] < x[j+1])
{
t = x[j];
x[j] = x[j+1];
x[j+1] = t;
}
}
}
for(i = 0; i < 15; i++)
{
System.out.println(x[i]);
}
}
}
12 Board Array Solution 2024-25

2018

import java.util.*;
class Student
{
public static void main()
{
Scanner sc = new Scanner(System.in);
Scanner sc1 = new Scanner(System.in);
System.out.println("Enter value of n: ");
int n=sc.nextInt();
String name[]=new String[n];
int totalmarks[]=new int[n];
int i;
for(i=0;i<n;i++)
{
System.out.print("Enter name: ");
name[i]=sc1.nextLine();
System.out.print("Enter marks: ");
totalmarks[i]=sc.nextInt();;
}
int sum=0;
for(i=0;i<n;i++)
{
sum=sum+totalmarks[i];
}
double avg=sum/(double)n;
System.out.println("Deviation of each students marks");
for(i=0;i<n;i++)
{
System.out.println(Math.abs(totalmarks[i]-avg));
}
System.out.println("Average= " + avg);
}
}
13 Board Array Solution 2024-25

2017

import java.util.*;
class MinMax
{
public static void main( )
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter size of array : ");
int n = sc.nextInt();
int x[] = new int[n];
int i;
for(i=0;i<n;i++)
{
System.out.println("Enter number : ");
x[i] = sc.nextInt();
}
int max =x[0], min = x[0], sum = 0;
for(i=0;i<n;i++)
{
sum = sum + x[i];
if(x[i] > max)
max =x[i];
if(x[i] < min)
min = x[i];
}
System.out.println("Maximum number is = "+ max);
System.out.println("Minimum number is = "+ min);
System.out.println("Sum is = "+ sum);
}
}
14 Board Array Solution 2024-25

import java.util.*;
class Selection
{
public static void main( )
{
Scanner sc = new Scanner(System.in);
String x[] = new String[40];
int i,j;
for(i= 0 ;i < 40 ; i++) // storing numbers in an array
{
System.out.print("Enter number : ");
x[i] = sc.nextLine();
}
String small;
int pos;
for(i = 0; i < 39 ; i++) // sorting the array elements
{
small = x[i];
pos = i;
for(j = i + 1; j <= 39 ; j++)
{
if(x[j].compareTo(small) > 0)
{
small = x[j];
pos = j;
}
}
String t = x[i];
x[i] = x[pos];
x[pos] = t;
}
for(i = 0; i < 40; i++)
{
System.out.println(x[i]);
}
}
}
15 Board Array Solution 2024-25

2016

import java.util.*;
class Wonders
{
public static void main()
{
String wonder[ ]={"CHICHEN ITZA","CHRIST THE REDEEMER","TAJMAHAL","GREAT WALL OF
CHINA","MACHU PICCHU","PETRA","COLOSSEUM"};
String country[ ] = {"MEXICO","BRAZIL","INDIA","CHINA","PERU","JORDAN","ITALY"};
Scanner sc = new Scanner(System.in);
System.out.print("Enter a country to be searched : ");
String value=sc.nextLine();
int i,pos= -1;
for(i=0;i<7;i++)
{
if(value.equalsIgnoreCase(country[i]))
{
System.out.println("Country = " + country[i]);
System.out.println("Wonder = " + wonder[i]);
pos = i;
break;
}
}
if(pos == -1)
System.out.println("Sorry not found");
}
}
16 Board Array Solution 2024-25

2015

import java.util.*;
class Q8
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int i,j;
String name[]=new String[20];
String t;
for(i=0;i<20;i++)
{
System.out.print("Enter Name of Student : ");
name[i]=sc.nextLine();
}
for(i=0;i<19;i++)
{
for(j=0;j<19-i;j++)
{
if(name[j].compareTo(name[j+1])<0)
{
t=name[j];
name[j]=name[j+1];
name[j+1]=t;
}
}
}
for(i=0;i<20;i++)
{
System.out.println(name[i]);
}
}
}
17 Board Array Solution 2024-25

2014

import java.util.*;
class BinarySearch
{
public static void main( )
{
Scanner sc = new Scanner(System.in);
int x[] = {1982,1987,1993,1996,1999,2003,2006,2007,2009,2010};
int pos = -1;
System.out.print("Enter the year of graduation: ");
int value = sc.nextInt();
int lb = 0,ub = x.length-1,mid;
while(lb <= ub)
{
mid = (lb+ub)/2;
if(value == x[mid])
{
pos = mid;
break;
}
else
if(value > x[mid])
lb = mid + 1;
else
ub = mid - 1;
}
if(pos != -1)
System.out.println("Record Exists");
else
System.out.println("Record Does Not Exists ");
}
}
18 Board Array Solution 2024-25

2013

import java.util.*;
class BubbleSort
{
public static void main( )
{
Scanner sc = new Scanner(System.in);
int x[]=new int[10];
int i,j,t;
for(i= 0 ;i < 10; i++)
{
System.out.print("Enter number : ");
x[i] = sc.nextInt();
}
for(i = 0; i < 9; i++)
{
for(j = 0; j < 9-i ; j++)
{
if(x[j] < x[j+1])
{
t = x[j];
x[j] = x[j+1];
x[j+1] = t;
}
}
}
for(i = 0; i < 10; i++)
{
System.out.println(x[i]);
}
}
}
19 Board Array Solution 2024-25

2012

import java.util.*;
class SearchCity
{
public static void main( )
{
String city[]=new String[10];
int std[]=new int[10];
Scanner sc = new Scanner(System.in);
Scanner sc1 = new Scanner(System.in);
int i;
for(i=0;i<10;i++)
{
System.out.println("Enter city and STD code");
city[i] = sc1.nextLine();
std[i]=sc.nextInt();
}
System.out.println("Enter the city whose std code you want");
String ct=sc1.nextLine();
int pos = -1;
for(i=0;i<10;i++)
{
if(ct.equalsIgnoreCase(city[i]))
{
System.out.println("SEARCH SUCCESSFUL");
System.out.println("City = " + city[i]);
System.out.println("Std codr = " + std[i]);
pos = i;
break;
}
}
if(pos == -1)
{
System.out.println("SEARCH UNSUCCESSFUL,NO SUCH CITY IN THE LIST");
}
}
}
20 Board Array Solution 2024-25

2011

import java.util.*;
class WeightSelectionSort
{
public static void main( )
{
Scanner sc = new Scanner(System.in);
int x[] = new int[10];
int i,j,t;
for(i= 0 ;i < 10; i++)
{
System.out.print("Enter Weight : ");
x[i] = sc.nextInt();
}
int small,pos;
for(i = 0; i < 9 ; i++)
{
small = x[i];
pos = i;
for(j = i + 1; j < 10 ; j++)
{
if(x[j] > small)
{
small = x[j];
pos = j;
}
}
t = x[i];
x[i] = x[pos];
x[pos] = t;
}
for(i = 0; i < 10; i++)
{
System.out.println(x[i]);
}
}
}
21 Board Array Solution 2024-25

2010

import java.util.*;
class BinarySearch
{
public static void main( )
{
int x[] = {5,7,9,11,15,20,30,45,89,97};
Scanner sc = new Scanner(System.in);
System.out.print("Enter no to be searched : ");
int value = sc.nextInt();
int l = x.length; //to find array length
int lb = 0, ub = l-1, pos = -1, mid;
while(lb <= ub)
{
mid = (lb+ub)/2;
if(value == x[mid])
{
pos = mid;
break;
}
else
if(value < x[mid])
ub = mid-1;
else
lb = mid + 1;
}
if(pos != -1)
System.out.println("Number found at position " + pos);
else
System.out.println("Number not found");
}
}
22 Board Array Solution 2024-25

import java.util.*;
class Merge
{
public static void main( )
{
int p[] = new int[6];
int q[] = new int[4];
int r[] = new int[10];
int i;
Scanner sc = new Scanner(System.in);
for(i = 0; i < 6; i++)
{
System.out.print("Enter number : ");
p[i] = sc.nextInt();
}
for(i = 0; i < 4; i++)
{
System.out.print("Enter number : ");
q[i] = sc.nextInt();
}
int k = 0;
for(i = 0; i < 6; i++)
{
r[k++] = p[i];
}
for(i = 0; i < 4; i++)
{
r[k++] = q[i];
}
for(i = 0 ; i< 10; i++)
{
System.out.println(r[i]);
}
}
}
23 Board Array Solution 2024-25

2009

import java.util.*;
class Student
{
public static void main( )
{
int roll[] = new int[50];
int s1[] = new int [50];
int s2[] = new int [50];
int s3[] = new int [50];
double avg[] = new double [50];
int i;
Scanner sc = new Scanner(System.in);
for(i = 0; i < 50; i++)
{
System.out.print("Enter roll no :");
roll[i] = sc.nextInt();
System.out.print("Enter marks in 3 subjects :");
s1[i] = sc.nextInt();
s2[i] = sc.nextInt();
s3[i] = sc.nextInt();
avg[i] = (s1[i] + s2[i] + s3[i])/3.0;
}
System.out.println("Roll no \t Average");
for(i = 0; i < 50; i++)
{
System.out.println(roll[i] + "\t" + avg[i]);
}
System.out.println("Roll no \t Average above 80");
for(i = 0; i < 50; i++)
{
if(avg[i] > 80)
System.out.println(roll[i] + "\t" + avg[i]);
}
System.out.println("Roll no \t Average below 40");
for(i = 0; i < 50; i++)
{
if(avg[i] < 40)
System.out.println(roll[i] + "\t" + avg[i]);
}
}
}
24 Board Array Solution 2024-25

2008

class Sorting
{
public static void main( )
{
String s[] = {"Delhi","Bangalore","Agra","Mumbai","Calcutta"};
int i, j;
String t;
for(i = 0; i < 4; i++)
{
for(j = 0 ; j < 4-i; j++)
{
if(s[j].compareTo(s[j+1]) > 0)
{
t = s[j];
s[j] = s[j+1];
s[j+1] = t;
}
}
}
for(i = 0; i < 5; i++)
{
System.out.println(s[i]);
}
}
}
25 Board Array Solution 2024-25

2007

class MinMax
{
public static void main( )
{
int x[] = {2,5,4,1,3};
int i, max = x[0] , min = x[0], sum = 0;
for(i = 0; i < 5; i++)
{
if(x[i] > max)
max = x[i];
if(x[i] < min)
min = x[i];
sum = sum + x[i];
}
System.out.println("Minimum value is " + min);
System.out.println("Maximum value is " + max);
System.out.println("Sum is " + sum);
}
}
26 Board Array Solution 2024-25

2006

import java.util.*;
class Student
{
public static void main( )
{
String name[] = new String[50];
int marks[] = new int[50];
Scanner sc = new Scanner(System.in);
Scanner sc1 = new Scanner(System.in);
int i;
for(i = 0; i < 50; i++)
{
System.out.print("Enter name : ");
name[i] = sc.nextLine();
System.out.print("Enter marks : ");
marks[i] = sc1.nextInt();
}
int sum = 0;
int max = marks[0];
String maxname = name[0];
for(i = 0; i < 50; i++)
{
sum = sum + marks[i];
if(marks[i] > max)
{
max = marks[i];
maxname = name[i];
}
}
double avg = sum/50.0;
System.out.println("Average marks " + avg);
System.out.println("Highest marks = " + max);
System.out.println("Name of the student securing highest marks = " + maxname);
}
}
27 Board Array Solution 2024-25

import java.util.*;
class Selection
{
public static void main( )
{
int x[] = new int[15];
Scanner sc = new Scanner(System.in);
int i, j, small,pos,t;
for(i = 0; i < 15; i++)
{
System.out.print("Enter no : ");
x[i] = sc.nextInt();
}
for(i = 0; i < 14 ; i++) // sorting the array elements
{
small = x[i];
pos = i;
for(j = i + 1; j <= 14 ; j++)
{
if(x[j] < small)
{
small = x[j];
pos = j;
}
}
t = x[i];
x[i] = x[pos];
x[pos] = t;
}
for(i = 0; i < 15; i++)
{
System.out.println(x[i]);
}
}
}
28 Board Array Solution 2024-25

2005

class Bubble
{
public static void main( )
{
int x[] = {5,3,8,4,9,2,1,12,98,16};
int i,j,t;
int len = x.length;
for(i = 0; i < len-1; i++)
{
for(j=0;j < len-1-i; j++)
{
if(x[j] > x[j+1])
{
t = x[j];
x[j] = x[j+1];
x[j+1]= t;
}
}
}
for(i = 0; i < len; i++)
System.out.println(x[i]);
}
}
29 Board Array Solution 2024-25

import java.util.*;
class LinearSearch
{
public static void main( )
{
String name[] = {"AMIT", "AJAY", "AMAN", "ANIL", "APURVA"};
long ph[] = {1234567,7895641,9874561,7457112,9678412};
int i, pos = -1;
Scanner sc = new Scanner(System.in);
System.out.print("Enter name to be searched : ");
String value = sc.nextLine();
for(i = 0; i < 5; i++)
{
if(value.equalsIgnoreCase(name[i]))
{
System.out.println("Search Successful");
System.out.println("Name is " + name[i]);
System.out.println("Telephone no is "+ ph[i]);
pos = i;
break;
}
}
if(pos == -1)
System.out.println("Name not enlisted ");
}
}

You might also like