All CoreJava TopicWise Program1
All CoreJava TopicWise Program1
2) WAP to enter the five elements in array and calculate the sum of all elements
10 20 30 40 50
2) WAP to enter the five elements in array and find out the maximum and minimum elements
Output like as
53641
Output like as
13456
e.g. declare the array of size 6 and store 5 values in it and last block should be empty
10 20 30 40 50
e.g. index = 2
Value = 100
When we insert the value on index then we need to shift the values from index to next index
e.g.
5 9 11 4 6
10 20 100 30 40 50
5). Write a program to enter the 5 values in ascending order and store in array and find out the
missing element from array?
1 5 9 13 17
2 3 4 6 7 8 10 11 12 14 15 16
e.g.
10 20 30 40 50
50 40 30 20 10
7) WAP to enter the 10 element array and print the occurrence of every element ?
a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9]
10 20 30 10 20 50 30 10 30 10
Output :
Element count
10 -------------------- 4
20 -------------------- 2
30 -------------------- 3
50 ------------------ 1
8) . Write a program in C to merge two arrays of same size sorted in decending order.
Test Data :
element - 0 : 1
element - 1 : 2
element - 2 : 3
element - 0 : 1
element - 1 : 2
element - 2 : 3
Expected Output :
332211
Test Data :
element - 0 : 25
element - 1 : 47
element - 2 : 42
element - 3 : 56
element - 4 : 32
Expected Output :
42 56 32
25 47
Test Data :
element - 0 : 1
element - 1 : 2
element - 2 : 3
element - 3 : 4
element - 4 : 5
Expected Output :
Test Data :
element - 0 : 2
element - 1 : 9
element - 2 : 1
element - 3 : 4
element - 4 : 6
Expected Output :
12) . Write a program in C to find a pair with given sum in the array.
Expected Output :
Pair of elements can make the given sum by the value of index 0 and 5
A majority element in an array A[] of size n is an element that appears more than n/2 times (and
Expected Output :
Expected Output :
12 14 18 20 22 25 27 0 3 6 9
Given a sorted array in ascending order and a value x, the ceiling of x is the smallest element in array
greater than or equal to x, and the floor is the greatest element smaller than or equal to x.
Expected Output :
16). Write a program in C to find the Floor and Ceil of the number 0 to 10 from a sroted array.
Expected Output :
17) Write a program in C to find the smallest missing element from a sorted array?
Expected Output :
18) Write a program in C to to print next greater elements in a given unsorted array. Elements for
which no greater element exist, consider next greater element as -1.
Expected Output :
10 10 13 13 13 -1
19) Write a program in C to find two elements whose sum is closest to zero
Expected Output :
[44, -46]
20) Write a program in C to find a subarray with given sum from the given array?
Expected Output :
[0..1] -- { 3 4 }
[0..5] -- { 3 4 -7 1 3 3 }
[3..5] -- { 1 3 3 }
[4..6] -- { 3 3 1 }
21) Write a program in C to find if a given integer x appears more than n/2 times in a sorted array
of n integers ?
Expected Output :
22) Write a program in C to find the maximum circular subarray sum of a given array.
Expected Output :
23) Write a program in C to move all zeroes to the end of a given array.
Expected Output :
2 5 7 8 4 -5 7 0 0 0
Expected Output :
25) Write a program in C to find out the maximum difference between any two elements such that
Expected Output :
26) Write a program in C to count all distinct pairs for a specific difference
Expected Output:
52376498
27) Write a program in C to find the maximum repeating number in a given array.
The array range is [0..n-1] and the elements are in the range [0..k-1] and k<=n..
Expected Output:
23353417777
Expected Output:
1546
1548
1568
1468
5468
Expected Output:
1 15 39 75 92
30) Write a program in C to find the minimum distance between two numbers in a given array.
Expected Output:
7 9 5 11 7 4 12 6 2 11
31) Write a program in C to rearrange positive and negative numbers alternatively in a given array
Output:
If positive numbers are more they appear at the end and for also negative numbers, they too appear
in the end of the array.
Expected Output:
-4 8 -5 -6 5 -9 7 1 -21 -11 19
-4 7 -5 1 -21 5 -11 8 -9 19 -6
32)Write a program in C to find the maximum for each and every contigious subarray of size k
Expected Output:
1 3 6 21 4 9 12 3 16 10
1 3 6 21 ----> 21
3 6 21 4 ----> 21
6 21 4 9 ----> 21
21 4 9 12 ----> 21
4 9 12 3 ----> 12
9 12 3 16 ----> 16
12 3 16 10 ----> 16
33) Write a program in C to convert the array in such a way that double its value and replace the
next number with 0 if current and next element are same and rearrange the array such that all 0's
Expected Output:
Given an unsorted array of integers, print the array after removing the duplicate elements from it.
Input: arr[] = { 1, 2, 5, 1, 7, 2, 4, 2}
Output: 1 2 5 7 4
Input: arr[] = { 3, 3, 4, 1, 1}
Output: 3 4 1
35) Write a program in C for a 2D array of size 3x3 and print the matrix ?
Test Data :
element - [0],[0] : 1
element - [0],[1] : 2
element - [0],[2] : 3
element - [1],[0] : 4
element - [1],[1] : 5
element - [1],[2] : 6
element - [2],[0] : 7
element - [2],[1] : 8
element - [2],[2] : 9
Expected Output :
The matrix is :
123
456
789
Test Data :
element - [0],[0] : 1
element - [0],[1] : 2
element - [1],[0] : 3
element - [1],[1] : 4
element - [0],[0] : 5
element - [0],[1] : 6
element - [1],[0] : 7
element - [1],[1] : 8
12
34
56
78
68
10 12
Test Data :
element - [0],[0] : 5
element - [0],[1] : 6
element - [1],[0] : 7
element - [1],[1] : 8
element - [0],[0] : 1
element - [0],[1] : 2
element - [1],[0] : 3
element - [1],[1] : 4
Expected Output :
The First matrix is :
56
78
12
34
44
44
Test Data :
element - [0],[0] : 1
element - [0],[1] : 2
element - [1],[0] : 3
element - [1],[1] : 4
element - [0],[0] : 5
element - [0],[1] : 6
element - [1],[0] : 7
element - [1],[1] : 8
Expected Output :
12
34
56
78
19 22
43 50
Test Data :
element - [0],[0] : 1
element - [0],[1] : 2
element - [1],[0] : 3
element - [1],[1] : 4
Expected Output :
The matrix is :
12
34
13
24
Test Data :
element - [0],[0] : 1
element - [0],[1] : 2
element - [1],[0] : 3
element - [1],[1] : 4
Expected Output :
The matrix is :
12
34
Test Data :
element - [0],[0] : 1
element - [0],[1] : 2
element - [1],[0] : 3
element - [1],[1] : 4
Expected Output :
The matrix is :
12
34
Test Data :
element - [0],[0] : 5
element - [0],[1] : 6
element - [1],[0] : 7
element - [1],[1] : 8
Expected Output :
The matrix is :
56
78
The sum or rows and columns of the matrix is :
5 6 11
7 8 15
12 14
43) Write a program in C to print or display the lower triangular of a given matrix.
Test Data :
element - [0],[0] : 1
element - [0],[1] : 2
element - [0],[2] : 3
element - [1],[0] : 4
element - [1],[1] : 5
element - [1],[2] : 6
element - [2],[0] : 7
element - [2],[1] : 8
element - [2],[2] : 9
Expected Output :
The matrix is :
123
456
789
123
056
009
element - [0],[1] : 2
element - [0],[2] : 3
element - [1],[0] : 4
element - [1],[1] : 5
element - [1],[2] : 6
element - [2],[0] : 7
element - [2],[1] : 8
element - [2],[2] : 9
Expected Output :
The matrix is :
123
456
789
100
450
789
Test Data :
element - [0],[0] : 1
element - [0],[1] : 0
element - [0],[2] : -1
element - [1],[0] : 0
element - [1],[1] : 0
element - [1],[2] : 1
element - [2],[0] : -1
element - [2],[1] : -1
element - [2],[2] : 0
Expected Output :
The matrix is :
1 0 -1
001
-1 -1 0
Test Data :
element - [0],[0] : 0
element - [0],[1] : 0
element - [1],[0] : 1
element - [1],[1] : 0
Expected Output :
47)Write a program in C to accept two matrices and check whether they are equal
Test Data :
element - [0],[0] : 1
element - [0],[1] : 2
element - [1],[0] : 3
element - [1],[1] : 4
element - [0],[1] : 2
element - [1],[0] : 3
element - [1],[1] : 4
Expected Output :
12
34
12
34
Test Data :
element - [0],[0] : 1
element - [0],[1] : 0
element - [0],[2] : 0
element - [1],[0] : 0
element - [1],[1] : 1
element - [1],[2] : 0
element - [2],[0] : 0
element - [2],[1] : 0
element - [2],[2] : 1
Expected Output :
The matrix is :
100
010
001
TProgram on Looping
1. Write a C program to print all natural numbers from 1 to n. - using while loop
2. Write a C program to print all natural numbers in reverse (from n to 1). - using while loop
4. Write a C program to print all even numbers between 1 to 100. - using while loop
12. Write a C program to find sum of first and last digit of a number.
20. Write a C program to print all ASCII character with their values.
Patterns Assignment
00
01 01
010 010
0101 0101
0101001010
11
12 21
123 321
1234 4321
1234554321
123454321
1234321
12321
121
BC
DEF
GHIJ
KLMNO
/*
ABCDEDCBA
ABCD DCBA
ABC CBA
AB BA
AA
*/
/*
BAB
CBABC
DCBABCD
EDCBABCDE
*/
/*
ABA
ABCBA
ABCDCBA
ABCDEDCBA
Q1. Write a program to create class name as Cube with two methods
int getCube(): this function can calculate cube of number and return it.
Q2. Write program to create class name as Factorial with two functions
int getFactorial(): this function can calculate factorial of number and return it.
Q3. Write program to create class name as CheckChar with two functions
boolean checkChar(): this function can check character is alphabet or digit of special symbol if
character is alphabet or digit return true if character is digit then return false.
Q3. Write program to create class name as FindMax with two functions
void setArray(int a[]): this function is used for accept array as parameter
int getMax(): this function can find the max value from array and return it.
Q4. Write program to create class name as SortArr with two functions
int [] getSortArray(): this function can perform sorting on array and return sorted array
Q5. Write program to create POJO class name as Employee with id,name and salary attribute and public
class Aptitude {
static int a;
int b;
System.out.println(a);
System.out.println(b);
Q6. Write program to create class name as CheckDuck with parameterized constructor
Boolean isDuckNumber(): this function check if number is duck return true otherwise return false.
Q7. Write program to create class name as Area with constructor overloading
Area(float radius): this function can accept radius as input and calculate circle Area
Area(int len,int width): this function can accept len and width as input and calculate area of
rectangle
Q8. Write program to create class name as MergeTwoArray with parameterized constructor
int [] getMergeArray(): this function merge two array in third array and return new merged array
Programming Question
________________________________________________________
Q1. Write a program to crate class name as Value with single function name as setValue(int,int) and
we have to create three child classes name as Add with function int getAdd() , Mul with function
getMul() and Div with function getDiv() and getAdd() function return addition of two value which is
inherited from Value class , getMul() function return multiplication of two values which is inherited
from Value class and gitDiv() function return division of two values which Is inherited from Value
class.
Q2. Write program to create class name Area with methods name as void setRadius(float radius) and
void setLengthWidth(int len,int wid) and two child classes name as Circle and Rectangle so you have
to define float getCircleArea() method in Circle child class and calculate area of circle and return it
and You have to define getRectArea() method in Rectangle class and calculate area of rectangle and
return it
Q3. Write Program create class name as ArrSum with method void setValue(int arr[]) you have to
create child class name as GetSum with method int getArrSum() you have to accept array values
Q4. Write program to Create class name as PersonalInfo with parameterized constructor
PersonalInfo(String name, String middlename, String lastname) and you have to create class name as
salary,String skillset) and you have to inherit PersonalInfo class in ProfessionalInfo and pass
parameter from ProfessionalInfo class to PersonalInfo using super() constructor and you have to
define void show() method in ProfessionalInfo and you have to show the all data in show() method.
Q5. Write Program to perform method overriding you have to create class name as ArrParent with
method
void arrangeSeq(): this method can display array as per user input sequence
You have to create two child class name as ArrangeAscendingOrder and you have to inherit
ArrParent class in it and override arrangeSeq() method in ArrangeAscendingOrder and sort array and
display in ascending order and you have to create one more class name ReverseArray and override
arrangeSeq() method from ArrParent and reverse array and display it.
Q6. Write Program to create abstract class name as Value with one abstract and one non abstract
method
void setValue(int ,int): this is non abstract method with two parameter
abstract int getResult(): this is abstract method
and you have two child class name as Power and you have to override getResult() method in Power
class and calculate power of two values and return it as well as SearchDigit and you have to override
getResult() consider first parameter of setValue() is number and second parameter is digit and you
have to search digit in number and return it and if digit not found return -1
Q7. Write Program to create class name as ArrAbs with two methods
void setArray(int arr[],int []): this function is used for accept array as parameter
abstract int [] getResultantArray(): this function can return resultant array from different child
classes.
You have to create two classes name as InterSection you have to override getResultantArray()
method in Intersection and perform intersection of array which we pass in setArray() function and
return it as well as you have to create one more class name as Union you have to override
getResultantArray() and perform union on two array and return resultant array
Program on String
Q1. WAP to input string and convert lower case string to upper case without using toUpperCase()
method?
Q2. WAP to input string and reverse the string without using any inbuilt function?
Q3. WAP to input two strings and compare then without using equals() or compareTo() method ?
Q4. WAP to input string and separate digit from string and calculate its sum?
Example: abc123mno456;
Output:1+2+3+4+5+6 =15
Q5. WAP to input string and count the words from a string using split() method?
Q6. WAP to input string and input second string and search second string in first input string using
indexOf() method?
Q7. WAP to input string and remove the white spaces from a string?
Example: abcmnoabc
Output: a2b2c2m1n1c1
Q10 Write a Java program to check whether a given string ends with another string.
Example:
Example:
Example:
Example:
Original String: Java is great and Java is fun and Java is powerful
Example
Example:
1. WAP to create thread using Thread class and display value from 1 to 10 with delay 10000
milliseconds?
2. WAP to create two threads name Even and Odd and Even thread print even values between
1 to 10 and Odd thread print odd values between 1 to 10 and use join() methods as well as
3. WAP to print the current working thread name and its priority?
Q1. Write a program to print all drives from your system and with its total space and free space?
Q2. Write program to create folder using File class and if folder is already present then show
Q3. Write program to create file using File class and if file is present then show message file is exist
and if file path is not found then handle exceptions at run time?
Q6. Create a file using a BufferedWriter class and store string data in it?
Q7. WAP to read file using a BufferedReader class and display it?
Q8. WAP to read file using BufferedReader and count its number of word in file, count number of
Q9. WAP to read file using a BufferedReader and reverse the every word from file and store in
another file?
Q10. WAP to read file using BufferedReader class and find the words whose ending with ing word
Q11. WAP to copy the image from D: drive and paste it on E drive?
Q1. WAP to create Vector and store 5 values in it and fetch it using Iterator, ListIterator,
Q2. WAP to create Vector and store 5 values in it and arrange all values in ascending order without
Q3. WAP to create Vector and store 5 values in it and find max and min value from collection
Q4. WAP to create ArrayList and store 10 values in it and find occurrence of every value in ArrayList?
Q5. WAP to create LinkedList and store 10 values in it and search particular value from LinkedList?
Q6.WAP to create ArrayList and store 5 employee objects in it and display it?
Q7. WAP to create ArrayList and store 5 player detail in it with id,name and run and search player
Q9. WAP to create LinkedHashSet and store 5 employee data in it and display it ?
Q10. WAP to create TreeSet and store 10 values in it and display it?