0% found this document useful (0 votes)
265 views8 pages

HandsOn 3

This document provides examples and instructions for 28 programming tasks. It describes tasks like counting word occurrences, checking for vowels, removing vowels from even positions, manipulating arraylists, checking for dashes in strings, calculating powers of array elements, removing duplicate characters, reversing and splitting strings, finding the difference between maximum and minimum array elements, and retrieving an element from a sorted string array. The document includes sample inputs, outputs, and class/method structures for each task.

Uploaded by

Dipak Nandeshwar
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)
265 views8 pages

HandsOn 3

This document provides examples and instructions for 28 programming tasks. It describes tasks like counting word occurrences, checking for vowels, removing vowels from even positions, manipulating arraylists, checking for dashes in strings, calculating powers of array elements, removing duplicate characters, reversing and splitting strings, finding the difference between maximum and minimum array elements, and retrieving an element from a sorted string array. The document includes sample inputs, outputs, and class/method structures for each task.

Uploaded by

Dipak Nandeshwar
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
You are on page 1/ 8

21.

String Occurences
Obtain two strings from user as input. Your program should count the number
of occurences of second word of second sentence in the first sentence.
Return the count as output. Note - Consider case.
Include a class UserMainCode with a static method countNoOfWords which
accepts two string variables. The return type is the modified string.
Create a Class Main which would be used to accept two Input strings and
call the static method present in UserMainCode.
Input and Output Format:
Input consists of two strings with maximum size of 100 characters.
Output consists of a single string.
Refer sample output for formatting specifications.
Sample Input 1:
abc bcd abc bcd abc abc
av abc
Sample Output 1:
4

Sample Input 2:
ABC xyz AAA
w abc
Sample Output 2:
0

22. Test Vowels


Write a program to read a string and check if given string contains exactly
five vowels in any order. Print ?Yes? if the condition satisfies, else
print ?No?.
Assume there is no repetition of any vowel in the given string and all
characters are lowercase.
Include a class UserMainCode with a static method testVowels which accepts
a string. The return type (Integer) should return 1 if all vowels are
present, else return 2.

Create a Class Main which would be used to accept a string and call the
static method present in UserMainCode.
Input and Output Format:
Input consists of a string.
Output consists of a string (?Yes? or ?No?).
Refer sample output for formatting specifications.
Sample Input 1:
acbisouzze
Sample Output 1:
Yes
Sample Input 2:
cbisouzze
Sample Output 2:
No

23. Removing vowels from String


Given a method with string input. Write code to remove vowels from even
position in the string.
Include a class UserMainCode with a static method removeEvenVowels which
accepts a string as input.
The return type of the output is string after removing all the vowels.
Create a Main class which gets string as an input and call the static
method removeEvenVowels present in the UserMainCode.
Input and Output Format:
Input is a string .
Output is a string .
Assume the first character is at position 1 in the given string.
Sample Input 1:
commitment
Sample Output 1:
cmmitmnt
Sample Input 2:
capacity
Sample Output 2:
cpcty

24. ArrayList Manipulation


Write a program that performs the following actions:
Read 2n integers as input.
Create two arraylists to store n elements in each arraylist.
Write a function generateOddEvenList which accepts these two arraylist as
input.
The function fetch the odd index elements from first array list and even
index elements from second array list and add them to a new array list
according to their index.
Return the arraylist.
Include a class UserMainCode with the static method generateOddEvenList
which accepts two arraylist and returns an arraylist.
Create a Class Main which would be used to read 2n integers and call the
static method present in UserMainCode.
Note:
- The index of first element is 0.
- Consider 0 as an even number.
- Maintain order in the output array list

Input and Output Format:


Input consists of 2n+1 integers. The first integer denotes the size of the
arraylist, the next n integers are values to the first arraylist, and the
last n integers are values to the second arraylist.
Output consists of a modified arraylist as per step 4.
Refer sample output for formatting specifications.
Sample Input 1:
5
12
13
14
15
16
2

3
4
5
6
Sample Output 1:
2
13
4
15
6

25. Dash Check


Write a program to read two strings and check whether or not they have
dashes in the same places. Print ?Yes? if the condition satisfies, else
print ?No?.
Include a class UserMainCode with a static method compareDashes which
accepts two strings. The return type (Integer) should return 1 if all
dashes are placed correctly, else return 2.
Create a Class Main which would be used to accept two strings and call the
static method present in UserMainCode.
Note: The strings must have exactly the same number of dashes in exactly
the same positions. The strings might be of different length.
Input and Output Format:
Input consists of two strings.
Output consists of a string (?Yes? or ?No?).
Refer sample output for formatting specifications.
Sample Input 1:
hi?there-you.
12--(134)-7539
Sample Output 1:
Yes
Sample Input 2:
-15-389
-xyw-zzy
Sample Output 2:
No

26. Sum of Powers of elements in an array


Given a method with an int array. Write code to find the power of each
individual element accoding to its position index, add them up and return
as output.
Include a class UserMainCode with a static method getSumOfPower which
accepts an integer array as input.
The return type of the output is an integer which is the sum powers of each
element in the array.
Create a Main class which gets integer array as an input and call the
static method getSumOfPower present in the UserMainCode.
Input and Output Format:
Input is an integer array.First element corresponds to the number(n) of
elements in an array.The next inputs corresponds to each element in an
array.
Output is an integer .
Sample Input 1:
4
3
6
2
1
Sample Output 1:
12
Sample Input 2:
4
5
3
7
2
Sample Output 2:
61

27. Duplicate Characters


Write a Program which removes duplicate characters from the string. Your
program should read a sentence (string) as input from user and return a
string removing duplicate characters. Retain the first occurance of the
duplicate character. Assume the characters are case ? sensitive.
Include a class UserMainCode with a static method removeDuplicates which
accepts a string. The return type is the modified sentence of type string.

Create a Class Main which would be used to accept the input string and call
the static method present in UserMainCode.
Input and Output Format:
Input consists of a string with maximum size of 100 characters.
Output consists of a single string.
Refer sample output for formatting specifications.
Sample Input 1:
hi this is sample test
Sample Output 1:
hi tsample

Sample Input 2:
ABC DEF

Sample Output 2:
ABC DEF

28. Reverse Split


Write a program to read a string and a character, and reverse the string
and convert it in a format such that each character is separated by the
given character. Print the final string.
Include a class UserMainCode with a static method reshape which accepts a
string and a character. The return type (String) should return the final
string.
Create a Class Main which would be used to accept a string and a character,
and call the static method present in UserMainCode.
Input and Output Format:
Input consists of a string and a character.
Output consists of a string (the final string).
Refer sample output for formatting specifications.

Sample Input:
Rabbit
Sample Output:
t-i-b-b-a-R

29. Difference between largest and smallest elements in an


array
Given a method taking an int array having size more than or equal to 1 as
input. Write code to return the difference between the largest and smallest
elements in the array. If there is only one element in the array return the
same element as output.
Include a class UserMainCode with a static method getBigDiff which accepts
a integer array as input.
The return type of the output is an integer which is the difference between
the largest and smallest elements in the array.
Create a Main class which gets integer array as an input and call the
static method getBigDiff present in the UserMainCode.
Input and Output Format:
Input is an integer array.First element in the input represents the number
of elements in an array.
Size of the array must be >=1
Output is an integer which is the difference between the largest and
smallest element in an array.
Sample Input 1:
4
3
6
2
1
Sample Output 1:
5
Sample Input 2:
4
5
3
7
2
Sample Output 2:
5

30. Find the element position in a reversed string array


Given a method with an array of strings and one integer (index) variable as
input. Write code to sort the given array in alphabetical order and return
the String of the given position in the array.
Include a class UserMainCode with a static method getPositionString which
accepts an array of strings and an integer variable as input.
The return type of the output is a String which is the value of given
position (index) from the array.
Create a Main class which gets string array and a integer variable as an
input and call the static method getPositionString present in the
UserMainCode.
Input and Output Format:
Input is an string array. First element in the input represents the size
the array
Assume the position of first element is 0.
Output is an integer which is the position of the string variable
Sample Input 1:
4
red
green
blue
ivory
ivory
Sample Output 1:
2
Sample Input 2:
3
grape
mango
apple
apple
Sample Output 2:
3

You might also like