+ All Categories
Home > Documents > Java Exercises

Java Exercises

Date post: 11-Oct-2015
Category:
Upload: gatesanyasi
View: 1,169 times
Download: 13 times
Share this document with a friend
Description:
Java Questions for practice
44
Module 1: Given two numbers a and b as input, return the sum of the numbers. Runs in a series The scores of a batsman in the five matches of a one day international series have been provided. Calculate the total number of runs the batsman scored in the series Compute polynomial Compute the value of the polynomial x^2y^2 +10xy   6x + 150y -100, where the inputs x and y have been provided. Seconds to hours Given the time in number of seconds, find out how many hours have been completed toHours(22125) = 6 toHours(3598) = 0 Hundreds digit Given a 4 digit number as input, find the value of its hundreds digit. significantDigit(3454) = 4 significantDigit(1999) = 9 Most Significant Digit Given a 4 digit number as input, find the value of its most significant digit. significantDigit(3454) = 3 significantDigit(1999) = 1 Required run rate  A team is chasing the target set in a one day international match. The objective is to compute the required run rate. The following have provided as input: target, maxOvers, currentScore, oversBowled. runrateRequired(326,49,210,33)=7.25 Difference in average The scores of a batsman in first and second innings of two test matches have been provided. Note that inn1 and inn2 refer to the first and second innings of the first test match. inn3 and inn4 refer to the first and second innings of the second test match. Compute the difference in average of the batsman while performing in the first innings of a test match vs the second innings. diffInAverage(134,29,56,48)=56.5 (The first innings average is (134+56)/2 = 95. The second innings average is (29+48)/2 = 38.5. The difference in averages is 95-38.5 = 56.5) Make a 3 digit number Given a digit as input, create a 3 digit number in which all the digits are the same as the input digit. make3DigitNum(4) = 444 make3DigitNum(1) = 111 Sum of 2 Digits Given a 2 digit number as input, compute the sum of its digits. Assume that the number has 2 digits. sum2Digits(12) = 3 (1+2 = 3)
Transcript

Module 1:Given two numbers a and b as input, return the sum of the numbers.Runs in a seriesThe scores of a batsman in the five matches of a one day international series have been provided. Calculate the total number of runs the batsman scored in the seriesCompute polynomialCompute the value of the polynomial x^2y^2 +10xy 6x + 150y -100, where the inputs x and y have been provided.Seconds to hoursGiven the time in number of seconds, find out how many hours have been completedtoHours(22125) = 6toHours(3598) = 0Hundreds digitGiven a 4 digit number as input, find the value of its hundreds digit.significantDigit(3454) = 4significantDigit(1999) = 9Most Significant DigitGiven a 4 digit number as input, find the value of its most significant digit.significantDigit(3454) = 3significantDigit(1999) = 1Required run rateA team is chasing the target set in a one day international match. The objective is to compute the required run rate. The following have provided as input: target, maxOvers, currentScore, oversBowled.runrateRequired(326,49,210,33)=7.25Difference in averageThe scores of a batsman in first and second innings of two test matches have been provided. Note that inn1 and inn2 refer to the first and second innings of the first test match. inn3 and inn4 refer to the first and second innings of the second test match.Compute the difference in average of the batsman while performing in the first innings of a test match vs the second innings.diffInAverage(134,29,56,48)=56.5 (The first innings average is (134+56)/2 = 95.The second innings average is (29+48)/2 = 38.5. The difference in averages is 95-38.5 = 56.5)Make a 3 digit numberGiven a digit as input, create a 3 digit number in which all the digits are the same as the input digit.make3DigitNum(4) = 444make3DigitNum(1) = 111Sum of 2 DigitsGiven a 2 digit number as input, compute the sum of its digits. Assume that the number has 2 digits.sum2Digits(12) = 3 (1+2 = 3)sum2Digits(10) = 1 (1+0 = 0)sum2Digits(96) = 15 (9+6 = 15)Sum of 4 DigitsGiven a number as input, compute the sum of its last 4 digits. Assume that the number has atleast 4 digits.sumOfDigits(12345) = 14 (last 4 digits 2+3+4+5 = 14)sumOfDigits(1000) = 1Area of a squareYou have been given 4 inputs x1,y1,x2 and y2. The points (x1,y1) and (x2,y2) represent the end points of the diagonal of a square. Return the area of the square.computeArea(0,0,5,5) = 25computeArea(2,3,8,15) = 90computeArea(1,1,4,3) = 6.5Make the right decimalGiven 3 digits a,b and c as input, return a double of the form a.bcmakeDecimal(4,8,1) = 4.81makeDecimal(0,0,6) = 0.06makeDecimal(9,0,7) = 9.07Make and add numbersGiven three digits as input, create a 4 digit number out of each input in which all the digits are the same. Then add all the 3 numbers and return the valueadd4DigitNums(1,2,3) = 6666 (as 1 will form 1111, 2 will form 2222, 3 will form 3333 and 1111+2222+3333 = 6666)add4DigitNums(4,5,6) = 16665 (as 4 will form 4444, 5 will form 5555, 6 will form 6666 and 4444+5555+6666 = 16665)Seconds to timeGiven the time of a day in number of seconds, convert it into time in hhmmss format. Note that the time is past noon, and hence the hours will never be less than 12.toHours(86399) = 235959toHours(46800) = 130000

Module 1bAnd of booleans Given three booleans as input, return the and of the all three booleansLarger than at least one Given three numbers as input, num, num1 and num2, return true if num is greater than atleast one of num1 and num2. Do not use if statement to solve this problem.largerThanOne(24,10,36) = truelargerThanOne(50,60,76) = falselargerThanOne(20,10,0) = trueLarger than exactly one Given three numbers as input, num, num1 and num2, return true if num is greater than exactly one of num1 or num2. Do not use if statement to solve this problem.largerThanExactlyOne(24,10,36) = truelargerThanExactlyOne(50,60,76) = falselargerThanExactlyOne(20,10,0) = falseNumbers in ascending orderGiven 3 numbers : num1, num2 and num3 as input, return true if they are in ascending order.Important:Do not use if statement in solution.inAscendingOrder(2,4,6) = trueinAscendingOrder(2,6,4) = falseNumbers in order Given 4 numbers : num1, num2, num3 and num4 as input, return true if they are in ascending order or in descending order.Important: Do not use if statement in solutioninOrder(2,4,6,6) = trueinOrder(8,7,7,0) = trueinOrder(2,4,7,6) = falseDry run IfDry runs for IfDivides (a,b) Given two numbers, return true if any one of them divides the other, else return falseIs Multiple of 3 and 7Given a number n, return true if it is divisible by either 3 or 7. For e.g., if n= 27, output is true. If n=58, output is false. If n=63, output is true.Largest number (of 3) Given three numbers as input, return the largest number.largest(10,20,15) = 20Has scored a century The scores of a batsman in his last three innings have been provided. You have to determine whether he has scored a century in the last three innings or not. If yes, return true else return false. For e.g. if the scores in the last three innings are 48,102,89 return true. If the scores are 99, 12, 0 return falseNumber of days in month Given the number of the month in 2013 (1 for January, 12 for December), return the number of days in it.
numOfDays(3) = 31numOfDays(6) = 30Same last digit Given 2 non negative numbers a and b, return true if both of them have the same last digit. For e.g. if the two numbers are 1268 and 80128 the output is true. If the two numbers are 901 and 9010 the output is falseLeap year Given a year, return true if it is a leap year otherwise return false.Please note that years that are multiples of 100 are not leap years, unless they are also multiples of 400.Boolean computation The inputs are three booleans a,b and c and a number n. If n=1, the return value is (a or b or c). If n=2 the return value is ((a and b) or c). If n=3, the return value is (a and b and c).Dry runs ElseDry runs for ElseLargest Number Given 5 numbers as input, find out the largest numberAddition of two fractions Given two fractions, check whether their sum is greater than or equal to 1. You have been provided 4 inputs, num1, den1, num2 and den2. The first fraction is num1/den1 and the second fraction is num2/den2. Add the fractions and return true if their sum is greater than or equal to 1 else return false. For e.g. if num1= 6, den1=11, num2 = 10, den2 = 21, their sum is 236/231 which is greater than 1 and hence the output is true.Add to form third Given three numbers a,b and c, return true if the sum of any two equals the third number. For e.g. if a=12,b=28,c=16 output is true (a+c=b).Scored century in two innings Given the scores of a batsman in four innings, return whether he scored at least two centuries or not.twoCentury(125,86,48,231) = truetwoCentury(25,50,98,123) = falsetwoCentury(128,145,23,177) = trueAbsolute Value of DiffGiven an input n, the return value is the absolute value of the difference between n and 144. However, if n is greater than 288, the return value is thrice the absolute value of the difference of n and 144.Check Combination 3 Given a, b and c, return true if any one of them can be formed by a mathematical operation using the other two numbers. the mathematical operations permitted are addition, subtraction, multiplication and division. For e.g if a=12, b = 15, c = 3 output is true (15-12 = 3).Closest Number Given three numbers, num1, num2 and target as input, the objective is to figure out which one of num1 or num2 is closest to target and return it. If both are equally close, return the larger number.closest(10,100,6) = 10closest(124,190,177)= 190Dry runs on charDry runs for CharDry runs on fnsDryRunFns0Change the case Given a char as input, if it is an alphabet change its case otherwise return it as it is. For e.g. if the input is a return A, if the input is K return k, if the input is 8 return 8.Is digit Given a char as input, return true if it is a digit (i.e. between 0 to 9).isDigit(a) = falseisDigit(2) = trueMiddle Char Given three chars as input, return the char that would come in the middle if the chars were arranged in order. Note that > operator can used for chars.middle(a,'x,'X) = amiddle(5,6,2) = 5Arithmetic OperationTwo numbers a and b and a char c have been provided as inputs. The char c represents a mathematical operation namely +,-,*,/,% (remainder). The task is to perform the correct operation on a and b as specified by the char c.compute(10,3,+') = 13compute(10,3,/') = 3compute(10,3,%') = 1Compute grade Given the marks of a student in five subjects, compute the overall grade.The grades will be on the basis of the aggregate percentage. if overall percentage >= 85%, grade is A, if it is >=75% it is B, >=60% is C, >=45% is D, if it is >=33% it is E else F.getGrade(87,79,98,82,75) = BLottery prizeJack bought a lottery ticket. He will get a reward based on the number of the lottery ticket. The rules are as follows- If the ticket number is divisible by 4, he gets 6- If the ticket number is divisible by 7, he gets 10- If the ticket number is divisible by both 4 and 7, he gets 20- Otherwise, he gets 0.Given the number of the lottery ticket as input, compute the reward he will receivelotteryReward(22) = 0lotteryReward(16) = 6lotteryReward(21) = 10lotteryReward(56) = 20Lottery prize 3 ticketsJack bought 3 lottery tickets. He will get a reward based on the number of the lottery ticket. The rules are as follows- If the ticket number is divisible by 4, he gets 6- If the ticket number is divisible by 7, he gets 10- If the ticket number is divisible by both 4 and 7, he gets 20- Otherwise, he gets 0.Given the numbers of the 3 lottery tickets as input, compute the total reward he will receive. In this problem define a function to compute the reward given the ticket number and use that function to calculate the total reward.lotteryRewardFor3(22,16,21) = 16lotteryRewardFor3(56,8,49) = 36Same last digitsYou have been given 4 numbers as input. Return true if any one the numbers has the same last 2 digits. For e.g. 123455 has the same last 2 digits (5 and 5) whereas 123545 does not (4 and 5). In this problem, define a function that check whether a number has the same two digits or not and returns true or false. Use that function to calculate for the 4 numbers.sameLastDigits(12445, 234454, 12781, 2300) = truesameLastDigits(12, 20, 5, 6) = falseDry run fns-1DryRunFns1Sum divisible by 11You have been given 4 numbers as input. Return true if you can find 3 numbers among them whose sum is divisible by 11. In this problem, define a function that takes 3 numbers as input and returns true if there sum is divisible by 11. Use this function to check for the 4 numbers.sumDivBy11(20,30,10,16) = true (as 20+30+16 = 66 which is divisible by 11)sumDivBy11(20,21,23,28) = false (as 20+21+23=64, 20+21+28=69, 21+23+28=71, 21+23+28=72 none of which are divisible by 11)Multiple Check Given a number n as input, return true if n is divisible by at least three and not divisible by at least one of 2,3,5,7 and 11.check(24) = false (divisible by 2 nos, not divisible by 3 nos)check(60) = true (divisible by 3 nos, not divisible by 2 nos)Double century and century A batsman played 4 innings in a test series. His scores have been provided as input. You have to determine whether he scored a double century and a century in the series. This means that the batsman should have had one score of at least 200 and a different score of at least 100. Please note that if the batsman scored two double centuries, then also the output will be true. For e.g. if the scores are 56, 208, 45, 110 the output is true. If the scores are 22, 0, 210, 45 the output is false.Add the last digitsGiven two numbers num1 and num2 as input, return the sum of the last 3 digits of num1 and the last 3 digits of num2. For solving this problem, define a function that returns the sum of the last 3 digits of a number provided as a parameter and use that function.sumLast3(123,8456) = 21 (123 -> 1+2+3 = 6, 8456 -> 4+5+6 = 15)Closest 100 Given a positive number as input find the multiple of 100 which is closest to it. Note that the multiple of 100 can be greater or smaller than the number. Also if the number is equidistant from the greater and smaller multiple, return the greater multiple.closest100(214) = 200closest100(277) = 300closest100(250) = 300closes100(300) = 300Close to century Given the score of a batsman and an integer n, return true if the score is within n of a multiple of 100. For e.g. if the score is 186 and n = 15, the output is true. If score is 392 and n=5, the output is false. If score is 409 and n = 12 the output is trueScored consecutive century Given the scores of a batsman in four innings, return true if he scored centuries in consecutive innings.consecutiveCentury(123,45,178,88) = falseconsecutiveCentury(123,23,145,221) = trueconsecutiveCentury(23,111,152,89) = trueSpecial 20A number is special20 if it is a multiple of 20 or if it is one more than a multiple of 20. Write a function that return true if the given non-negative number is special20.special20(21) = truespecial20(100) = truespecial20(99) = falseDiff 25Given three ints as input , return true if one of them is 25 or more less than one of the other numbers.diff25(1, 13, 40) = truediff25(13, 1, 25) = falsediff25(40, 60, 2) = trueLottery ticketYou have purchased a lottery ticket showing 3 digits a, b, and c. The digits can be 0, 1, or 2. If they all have the value 2, the result is 10. Otherwise if they are all the same, the result is 5. Otherwise if both b and c are different from a, the result is 1. Otherwise the result is 0.lotteryTicket(2, 2, 2) = 10lotteryTicket(4, 2, 1) = 1lotteryTicket(2, 2, 1) = 0lotteryTicket(0, 0, 0) = 5More same, more prizeYou have a green lottery ticket, with ints a, b, and c on it. If the numbers are all different from each other, the result is 0. If all of the numbers are the same, the result is 20. If two of the numbers are the same, the result is 10.greenTicket(1, 2, 3) = 0greenTicket(2, 2, 2) = 20greenTicket(1, 1, 2) = 10BlackjackGiven 2 int values greater than 0, return whichever value is nearest to 21 without being greater than 21. Return -1 if the values are greater than 21. Also return -2 if both the values are same and less or equal to 21.blackjack(18,21) = 21blackjack(21,16) = 21blackjack(22,23) = -1blackjack(12,22) = 12blackjack(20,20) = -2

Module1cSum of numbers Given a number n as input, output the sum of numbers from 1 to n.sum(3) = 6sum(355) = 63190Sum of Squares Given two numbers n1 and n2 such that n2>n1, find sum of squares of all numbers from n1 to n2 (including n1 and n2).computeSumofSquares(1,5) = 55Sum of certain numbers Given a number n as input, find the sum of all numbers from 1 to n which are not divisible by either 2 or 3.sum(10) = 13 (1+5+7)sum(20) = 73Count factors Given a number n as input, find the count of its factors other than 1 and n.countOfFactors(144) = 13 (2,3,4,6,8,9,12,16,18,24,36,48,72)countOfFactors(13) = 0Count common factors Given two numbers n1 and n2 as input, find the count of common factors of n1 and n2. Note 1 and the number itself have not been considered as factors in this problem.countFactors(144,12) = 4 (2,3,4,6)countFactors(144,13) = 0Is Prime Given a number n as input, return whether the number is a prime number or not. Please note that 1 is not a prime numberNth Power Given a number a, compute the nth power of aSum of Digits (with no. of digits) Given 2 inputs, a number n and the number of digits it has d , find the sum of its digits. For e.g. if n=123, d =3, the output is 1+2+3=6. If n=45891 and d=5 the output is 4+5+8+9+1=27.Reading links While While loopDry run While DryRunWhileDry run For (2) DryRunFor_2No. of 9s in number (No. of digits specified) Given 2 inputs, a number and the number of digits it has , find out the no. of 9s in the number. For e.g. if number=80123 and digits=5, the output is 0. If number=909090 and digits=6, the output is 3.Perfect Number A perfect number is a positive integer that is equal to the sum of its factors. For example, 6 is a perfect number because 6=1+2+3; but 24 is not perfect because 24n1, find the sum of total number of fizz, buzz and fizzbuzz.countFizzBuzz(1,20) = 9 (fizzbuzz : 15; fizz : 3, 6, 9, 12, 18; buzz : 5, 10, 20)Is Fizz A number is defined as a Fizz if it is a multiple of 3 or has the digit 3 in it.Given a number as input, determine whether it is a Fizz or not.isFizz(12) = trueisFizz(13) = trueisFizz(14) = falseDry run While These are exercises that provide dry run practise. No code needs to be written and hence there is no need to upload the code in this problem.Sum of Digits Given a number n, find the sum of its digits.sumDigits(12345) = 15sumDigits(1000010) = 2Count digits Given a number as input, count the number of digits it has. You can assume that the number is not negative.countDigits(0) = 1countDigits(1234) = 4Count the digit Given a number n and a digit d as input, find the number of time d occurs in n. You can assume that the number is non-negative.findDigitCount(2001,0) = 2findDigitCount(0,0) = 1findDigitCount(9,2) = 0Binary to decimal Given a number as binary (digits 0 and 1), convert it to its corresponding decimal number.convertBinaryToDecimal(1001) = 9convertBinaryToDecimal(11111) = 31Reading links Break, return Break, returnDry run functionsDryRunFnsAnyone prime Given three numbers as input, return true if at least one of them is a prime number. For solving this problem, define a function that checks whether a number is a prime or not and use that function.anyonePrime(12,23,45) = trueanyonePrime(97,83,71) = trueanyonePrime(169,361,121) = falseSame first digit Given three numbers as input, return true if the first digit of any two of them is the same. The first digit of 2345 is 2, of 981201 is 9. Assume all the numbers are positive integers greater than 0. For solving this problem, define a function that computes the first digit if a number and use that function.sameFirstDigit(981231,7810009,9) = true (981231 and 9 have the same first digit, which is 9).sameFirstDigit(122341,2231,341) = falseNext multiple of 3 and 7 Given a number num as input, find the smallest number greater than num that is a multiple of both 3 and 7.findNextMultiple(12) = 21findNextMultiple(30) = 42Middle Digit Given a number as input, find its middle digit. If number of digits in the number is even, return average of the two middle digits.If n has only one digit, return that digit. You can assume the number to be non-negative.findMiddleDigit(12345) = 3findMiddleDigit(125839) = 6 (average of 5 and 8)findMiddleDigit(0) = 0Check Combination 3 Given a, b and c, return true if any one of them can be formed by a mathematical operation using the other two numbers. the mathematical operations permitted are addition, subtraction, multiplication and division. For e.g if a=12, b = 15, c = 3 output is true (15-12 = 3).Prime, Perfect, Has Digits Given two integers, n and checkType as input, return- If checkType =1, return whether n is a prime or not- If checkType =2, return whether n is a perfect number or not- If checkType =3, return whether n has a 3,6 or 9 in its digits or not- Otherwise, return falsecheck(23,1) = true;check(23,2) = false;check(23,3) = true;Check combination 4 Given 4 numbers a, b, c and d as input, return true if we can find a set of 3 numbers among them with the property that : One of numbers can be formed by a mathematical operation using the other two numbers. The mathematical operations permitted are addition, subtraction, multiplication and division.check4(8,16,48,2) = true (because we can form a set of three numbers (8,16,2) where 16=8*2)check4(8,16,48,12) = falseCheck combination 5 Given 5 numbers a, b, c, d and e as input, return true if we can find a set of 3 numbers among them with the property that : One of numbers can be formed by a mathematical operation using the other two numbers. The mathematical operations permitted are addition, subtraction, multiplication and division.check5(3,7,9,48,2) = true (because we can form a set of three numbers (7,9,2) where 2=9-7)check5(3,7,9,48,5) = falseDry run Nested loopsDryRunFor_NestedSum rounded numbersRound a number to the next multiple of 10 if its ones digit is 5 or more, othwerise round it the previous multiple of 10.So, 25 and 26 round to 30 where as 23 and 24 round to 20. 20 also rounds to 20. You have been given 4 ints as input. Round each of the input values and return their sum.roundedSum(11,15,23,30) = 80 (11 rounds to 10, 15 to 20, 23 to 20 and 30 to 30)roundedSum(1,3,7,9) = 20Compute the HCF Given 2 numbers a and b, compute the HCF (Highest Common Factor) of a and b. HCF is the largest number that divides both a and b. For e.g. the HCF of 144 and 162 is 18. The HCF of 32 and 81 is 1.HCF can be computed as follows. If a=b, the HCF(a,b)=a. If a>b and b divides a, HCF (a,b) = b, else HCF(a,b)=HCF(b,a%b)hcf(100,125)=25hcf(24,144)=24hcf(97,41)=1Count Fizz A number is defined as a Fizz if it is a multiple of 3 or has the digit 3 in it.Given a number num as input, count the number of Fizz between 1 and num.countFizz(15) = 6 (3,6,9,12,13,15)countFizz(100) = 45 (3,6,9,12,13,15, 18,21,23,24,27,30,31, 32,33,34,35,36,37,38,39,42, 43,45,48,51,53, 54,57,60,63,66,69, 72,73,75,78,81,83, 84,87,90,93,96,99)Count the primes in between Given two numbers n1 and n2 as input, count the number of primes between n1 and n2. Note that n2>=n1. Also both n1 and n2 will be included in the count, if they are primes.countPrimes(31,41) = 3 (31,37,41)countPrimes(1,50) = 15 (2,3,5,7,11,13,17,19,23,29,31,37,41,43,47)Compute nth prime Given an input n, find out the nth primeSum of Digits (Repeated) Given a number n, find the sum of its digits. If the sum is greater than 9, repeat the same process till it becomes a single digit. For e.g. if the number is 123 the output is 1+2+3=6, if the input is 45891, the output is 4+5+8+9+1=27 -> 2+7=9Sum of Primes Given a number n, return true if there exist a and b such that a+b=n and both a and b are prime numbers.isSumOfPrimes(15) = true (2+13=15)isSumOfPrimes(17) = falseSuper divideA positive int is called super-divide if every digit in the number divides the number. So for example 128 divides itself since 128 is divisble by 1, 2, and 8. Note that no number is divisible by 0. Given a number as input, determine if it is a super-divide.superDivide(184) = truesuperDivide(39) = falsesuperDivide(120) = falseSum numbers, check digitsGiven 2 non-negative ints, a and b, return their sum, so long as the sum has the same number of digits as a. If the sum has more digits than a, just return a.sumLimit(2, 3) = 5sumLimit(8, 3) = 8 (as 8+3 = 11 which has 2 digits which a = 8 has 1 digit)sumLimit(8, 1) = 9Are all factors prime Given a number n, return true is all the factors of n are prime numbers. Note that 1 and the number itself are not considered as factors in this problem.areAllFactorsPrime(22) = true (2,11 are prime)areAllFactorsPrime(25) = true (5 is a prime)areAllFactorsPrime(32) = false (4,8,16 are not prime)Check sequence in number Given two numbers, n and target, as input, check whether the number target can be found in n or not. For e.g. if n=1234, the return value will true if target is 12, 23 or 34. For all other values of target, the return value will be false.Note that target is always a two digit number.hasSequence(234567,45) = true (as 45 is there is 234567)hasSequence(234567,54) = false (as 54 is not there is 234567)Rotating digits Given a number n as input, the objective is to figure out whether any rotation of the digits of n is a prime number or not. A rotation is formed by the removing the last digit and putting it in front. For e.g. the rotations of n=1639 are 1639, 9163, 3916 and 6391. Note that the count of possible rotations is equals to the count of digits in the number.It can be assumed that none of the digits in the input number is a zero.isPrimePossible(91) = true (as 19 is a prime)isPrimePossible(824) = falseisPrimePossible(1462) = true (4621 is a prime)Maximum number of factors Given a number n as input, find the number x, such that n=0, create an array with the pattern {1,1,2,1,2,3, 1,2,3..n}.domino(1) = {1}domino(2) = {1,1,2}domino(3) = {1,1,2,1,2,3}domino(4) = {1,1,2,1,2,3,1,2,3,4}Reverse an array Given an array of integers as input, output an array which has the elements in reverse order.reverse({1,2,3,4})={4,3,2,1}reverse({8,10,12,-8,-10})={-10,-8,12,10,8}Dry run Array Passing(1) DryRun_ArrayPassingSimilar 3Given an array of ints as input, find out if the array contains either 3 even or 3 odd numbers which are all next to each other.similar3({2,1,3,5,4,8,11}) = true // 1,3,5 3 odd numbers are next to each othersimilar3({10,15,20,25,30,36,40,45}) = true // 30,36,40 3 even numbers are next to each othersimilar3({11,31,51}) = truesimilar3({1,3,2,4,5,7,6,8}) = falseConsecutive 4Given an array of ints as input, find out if the array contains, 4 consective numbers together like 2,3,4,5 or 33,34,35,36.consecutive4({1,2,4,8,11,12,13,14,15,20,21}) = true // 11,12,13,14 are 4 consective numbers that appear togetherconsecutive4({3,5,7,9,11,12,13,16,20}) = falseconsecutive4({10,9,8,7,6,5}) = falseMove even numbers to the frontGiven an array of ints as input, return an array that contains the same numbers as that in the input array, but rearranged so that all the even numbers are in front and the odds numbers are at the back. Note that the order of the even numbers and odd numbers should be maintained i.e. if an even number n1 that appears before an even number n2 in the input, then in the output array n1 should appear before n2. The same is true for odd numbers. Also note that in this problem you should not create any new array.evenInFront({1,2,3,4,5,6,7,8,10,12}) = {2,4,6,8,10,12,1,3,5,7}evenInFront({2,1,2,1,2,1}) = {2,2,2,1,1,1}evenInFront({10,8,20,4,24}) = {10,8,20,4,24}evenInFront({5,3,7,1}) = {5,3,7,1}Count same numbersYou have been two arrays of ints as input. Both the arrays are sorted in ascending order. Return the number of distinct ints that appear in both the arrays. You need to solve it in a single pass over both the arrays.sameNumbers({1,2,4,8,16,32,64},{2,2,2,4,4,4,6,8,10,12,14,28,32})=4sameNumbers({1,3,5,7,9,11},{2,3,4,5,5,6,6,7,7,13,15})=3Array2 in Array1Given two arrays of ints sorted in ascending order, arr1 and arr2, return true if all of the numbers in arr2 are there in arr1. Note that you can assume that arr1 has only distinct values. You should solve it in a single pass of both arrays, by taking advantage of the fact that the arrays are already sorted in ascending order. Single pass means that you have only one loop (which is not nested) where you looking at the elements of the array.hasInside({1,2,3,4,5,6,7}, {2,4,6}) = truehasInside({1,2,3,4,5,6,7}, {2,4,6,8}) = falseCount clustersYou have been given an array of Strings as input. Define a clusters in an array as a series of two or more adjacent elements with the same value. The objective is count the number of clusters in the given array.clusters({India,USA,USA,India,India,UK}) = 2 (first cluster is USA,USA, second cluster is India,India)clusters({India,USA,USA,USA,India,USA,USA,India,UK}) = 2 (first cluster is USA,USA,USA second cluster is USA,USA)clusters({111,111,111,111,111,111}) = 1Join n alphabetsYou have been two arrays of strings as input. In both the arrays, each element is a lower case alphabet. Also the elements of both the arrays are in alphabetical order. You have also been provided an int n as input. Return a new string array containing n elements which have been picked from the initial elements of arr1 and arr2. Also the output array should be sorted in alphabetical order.joinAlphabets({a,c,x}, {b,f,w}, 3) = {a,b,c}joinAlphabets({a,c,y}, {c,f,t}, 3) = {a,c,c}joinAlphabets({f,g,z}, {c,f,g}, 5) = {c,f,f,g,g}Join n alphabets (no duplicates)You have been two arrays of strings as input. In both the arrays, each element is a lower case alphabet. Also the elements of both the arrays are in alphabetical order. You have also been provided an int n as input. Return a new string array containing n elements which have been picked from the initial elements of arr1 and arr2. Also the output array should be sorted in alphabetical order and should not have duplicates.joinAlphabets({a,c,x}, {b,f,w}, 3) = {a,b,c}joinAlphabets({a,c,y}, {c,f,t}, 3) = {a,c,f}joinAlphabets({f,g,t,u}, {c,f,g,u}, 4) = {c,f,g,t}Dry run Array Passing (2) DryRun_ArrayPassing_2Any duplicates in array Given an array of integers, check whether any number has been repeated in the array. That is, whether the array has any duplicates.anyDuplicates({1,2,3,4})=falseanyDuplicates({11,22,33,44,22)=trueAppend two arrays Given two arrays, arr1 and arr2 as input, return an array which has the values of arr1 followed by those of arr2.join({1,14,15,2,3},{20,30,40,30,20}) = {1,14,15,2,3,20,30,40,30,20}Form largest number An array of size 10 has been provided as input. Assuming that the value of array at index i, denotes the number of times digit i can be used, the objective is to form the largest possible number using all the digits.form({1,2,3,4,5,6,1,2,3,4})=9999888776555555444443333222110form({1,1,1,1,1,1,1,1,1,1})=9876543210Is the array of numbers sorted Given an array of integers as input, return true if the array is sorted. Note that the array can be sorted in either ascending or descending order.isSorted([1,3,5,7})=trueisSorted({11,9,2,-5})=trueisSorted({1,2,3,4,-1,-2})=falseRemove Zeros Given an array of integers return an array in the same order with all 0's removed.remove({1,2,3,4,5,0,1,2,0,0,2})= {1,2,3,4,5,1,2,2} remove({0,0,1,2})={1,2}remove{0,0,0,0}={}Third largest number in array Given an array of integers, find out the third largest value in the arraythirdLargest{0,21,19,0,17,15,0,11,908,4,299,110}=110Remove all 3s Given an array on numbers as input, remove all elements from the array which are either multiple of 3 or have the digit 3 in them. For e.g. 13 and 15 will be both removed from the array if they are present.remove({21,19,17,23,15,11,8,4,31})={19,17,11,8,4}Array of digits in string Given a string which contains a number as input, the objective is to create an array arr, such that arr[i] represents the number of times the digit i appeared in the string. Note that the maximum value of i in arr[i] will be 9 as the digits are 0,1,2,3,4,5,6,7,8,9.getDigitArray(9988776655)={0,0,0,0,0,2,2,2,2,2}getDigitArray(123456789013579)={1,2,1,2,1,2,1,2,1,2}Dry run 2D array DryRun2DArrayLargest number in 2D arrayGiven a 2D array consisting of ints as input, return the largest int in it.largestIn2D({{1,2,3},{4,6,8},{3,5,7},{1,4,0}}) = 8Matrix Addition Given two matrices M1 and M2, the objective to add them. Each matrix is provided as an int[][], a 2 dimensional integer array. The expected output is also 2 dimensional integer array.Words to 2D charsGiven a para of words (separated by space), create a 2D array where each array in it represents the word. Note that the words are of the same size.to2DChars(bat sat put mat) = {{b,'a,'t},{s,'a,'t},{p,'u,'t},{m,'a,'t}}to2DChars(hi is to) = {{h,'i},{i,'s},{t,'o}}Compute mid value of array Given an integer array with odd number of values, find out the value of the middle number if the array was sorted. For e.g. if the length of array is 11, the value of the 6th element when sorted needs to be found. Note that whether the array is sorted in ascending or descending order, the middle element will remain the same.midNumber({2,4,6,8,10,1,3,5,7,9,0})=5Remove duplicates from array Given an array of numbers as input, return an array with all the duplicate values removed.remove({1,2,3,4,0,1,4,3,2)}={1,2,3,4,0}Most frequent digit Given a number, the objective is to find out the most frequently occuring digit in the number. If more than 2 digits have the same frequency, return the smallest digit.getFreqDigit(9988776655)=5getFreqDigit(127341743217)=1Split array into two Given an array of numbers as input, return true if it can be split at a point such that the sum of the two parts is equal.canSplit({1, 1, 1, 2, 1,3,4,5,3,4,1})=truecanSplit({1,2})=falseDry run Array Passing (3) DryRun_ArrayPassing_3Join 2 sorted arrays Given two arrays, arr1 and arr2, that have been sorted in descending order, output an array which appends the values from both arr1 and arr2 while being sorted in descending order.join({21,19,17},{111,21,10})={111,21,21,19,17,10}Array of factors Given a number n as input, return an array consisting of all the factors of n. The factors should be in ascending order. Note that 1 and n are also factors of n.getFactors(967)={1,967}getFactors(1440)={1,2,3,4,5,6,8,9,10,12,15,16,18,20,24,30,32,36,40,45,48,60,72,80,90,96,120,144,160,180,240,288,360,480,720,1440}All primes between Given two numbers n1 and n2 as input, return an array containing all the primes between n1 and n2 (Note that both n1 and n2 can be included in the array if they are prime). Also, the primes in the array need to be in ascending order.getPrimes(967,1041)={967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039}getPrimes(6,11)={7,11}Array contains the other Given two arrays outer and inner as input, determine whether the outer array contains all the values of inner array. Both the arrays, outer and inner, are sorted in the same order. That is, if outer is sorted in ascending order, inner will also be sorted in ascending order.Note that this problem has to be solved without visiting the value of anu element of either array more than once.contains({2,4,6,7,10},{6,7}) = truecontains({40,30,20,10,-10},{40,20,10,4}) = falseWord Puzzle Up, Down, Left, Right A rectangular grid of words has been laid out before you. Also provided is a list of words to find in the grid. Your job is to find which of these words appear in the grid. The words can appear in a straight line (left, right, up or down). For e.g. if the grid of words is E L P P AR A E V VX Y A X WM U C L OG I H S A and the list of words is APPLE,BANANA,GUAVA,PEACH,PEAR,PLUM, the words APPLE and PEACH can be found in the grid.The grid is provided as a 2 dimensional array of char like {{E,'L,'P,'P,'A},{R,'A,'E,'V,'V},{X,'Y,'A,'X,'W},{M,'U,'C,'L,'O},{G,'I,'H,'S,'A}} and the list is provided like a string of comma demarcated words like APPLE,BANANA,GUAVA,PEACH,PEAR,PLUM. The output is a string which contains the words found in the grid in the same order as they appear in the list. In this example the output will be APPLE,PEACH.Multiply large numbers The objective of this exercise is two multiply any 2 numbers. The numbers can be extremely large (i.e. run into hundreds of digits) and are provided as strings. The expected output is a string which represents the product of the two numbers.multiply(268435456,524288)=140737488355328multiply(12321412423524534534543,0)=0

Module 4aCreate a class TwoDPointCreate a class TwoDPoint that contains two fields x, y which are of type int. Define another class TestTwoDPoint, where a main method is defined. The main method should create two TwoDPoint objects, assign them values 2,2 and 3,3 and print them.TwoDPoint-2 Adding to the previous problem, modify the class TestTwoDPoint and add a function to it. This function takes two ints as input and returns a TwoDPoint.TwoDPoint-3 Adding to the previous problem, modify the class TestTwoDPoint and add another function to it. This function takes two TwoDPoints as input and returns the TwoDPoint that is farthest from the point (0,0).TwoDPoint-4Adding to the previous problem, modify the class TestTwoDPoint and add another function to it. This function takes two TwoDPoints as input and returns a new TwoDPoint whose x value is the sum of x values of the input TwoDPoints and whose y value is the sum of the y valaues of the input TwoDPoints.Create a class StudentCreate a class Student that contains the following fieldds name (of type string), marks(of type int[]). Define another class TestStudent, where a main method is defined. The main method should creates a Student object with name as Bill and marks as {88,92,76,81,83} and print it.Student-2 Adding to the previous problem, modify the class TestStudent and add a function totalMarks(Student st). This function takes a Student as input and returns the total marks of the student.Student-3 Adding to the previous problem, modify the class TestStudent and add a function betterStudent(Student st1, Student st2). This function takes two Students as input and returns the Student with the higher total marks.Student-4 Adding to the previous problem, modify the class TestStudent and add a function createStudent(String nameStr, String marksStr). This function creates and return a new Student. The name of the new Student is nameStr and the marks are determined from comma separated string marksStr. For e.g. marksStr can be 68,72,76,81,73.Student-5 Adding to the previous problem, modify the class TestStudent and add a function display(Student st). This function takes a Student as input and prints it.Dry run Objects(2)DryRunObjects_1_2Create a class RectangleCreate a class Rectangle that contains the following fields length(of type int), breadth(of type int). Define another class TestRectangle, where a main method is defined. The main method should creates a Rectangle object with length = 10 and breadth = 20 and print it.Rectangle-2Adding to the previous problem, modify the class TestRectangle and add a function createStudent(int ln, in br). This function creates and return a new Rectangle.Rectangle-3Adding to the previous problem, modify the class TestRectangle and add a function computeArea(Rectangle rect). This function returns the area of the Rectangle rect. Also add another function computePerimeter(Rectangle rect) which returns the perimeter of the Rectangle rectRectangle-4Adding to the previous problem, modify the class TestRectangle and add a function createRectangles(int[] lengths, int[] breadths). This function returns an array of Rectangle (Rectangle[]) which corresponds to the lengths and breadths being input. Note that the length of both the input arrays is the same and you will create the same of the new Rectangle.Rectangle-5Adding to the previous problem, modify the class TestRectangle and add a function largestPerimeter(Rectangle[] rects). This function returns the Rectangle with the largest perimeter in the input rectangles.Rectangle-6Adding to the previous problem, modify the class TestRectangle and add a function largestArea(Rectangle[] rects). This function returns the Rectangle with the largest area in the input rectangles.Dry run Objects(3)DryRunObjects_1_3DryRunObjects_1_4Create a class CircleCreate a class Circle that contains the following field radius(of type int). In the class Circle, also define the following methods- area : which returns the area of the circle. Assume pi = 3.14- perimeter : which returns the perimeter of the circle.Define another class TestCircle, where a main method is defined. The main method should create a Circle object with radius = 5 and display the area and perimeter of the circle. Note that in calculating the area and perimeter use the corresponding methods defined in Circle class.Circle 2Adding to the previous problem, Modify the class TestCircle. Add to it a function largerCircle(Circle circle1, Circle circle2), which returns the Circle with the larger area. Note that while calculating the area, you have to use the method defined in Circle class.Create a class ResultCreate a class Result that contains the following fields marks(of type int[]). The int[] marks contains the marks obtained by a student in the various examinations that were conducted. In the class Result also define the following functions- maxMarks : which returns the maximum marks scored (it is the maximum value in the int[] marks).- avgMarks : whichs returns the average marks scored in the exams.- totalMarks : whichs returns the total marks scored in the exams.Also define the class TestResult in which there is function which created a new Result and displays the values of max marks and average marks. Note that for calculating max marks and average marks, you should use the methods defined in the class Result.Result 2Adding to the previous problem, Modify the class TestResult. Add to it a function betterResult(Result res1, Result res2), which returns the better Result. Better result is defined as the result the higher total marks. If total marks are the same, then it is the one with the higher maximum marks. Note that while calculating total marks, you have to use the method defined in the Result class.Result 3Adding to the previous problem, Modify the class TestResult. Add to it a function bestResult(Result[] results), which returns the best Result. The best result is defined as the result with the highest average marks. Note that while calculating average marks, you have to use the method defined in the Result class. Also, you can assume that no two results have the same average marks.Create the classes Item and ShoppingCartCreate a class Item which refers to an item in the shopping cart of an online shopping site like Amazon. The class Item has the fields name (of type String), productId (of type String), price (of type double), quantity (of type int), amount (of type double). The field amount is calculated as price * quantity.Also define a class ShoppingCart which refers to the shopping cart of a customer at Amazon. The class ShoppingCart has the fields items (of type Item[]), totalAmount (of type double).Also define a class TestCart which has a function makeCart(String[] itemData) which takes the information about the shopping cart of a customer as input and returns an object of type ShoppingCart.The input String[] items, consists of an array of String where each String provides information on an item in the manner name,id,price, quantity. For e.g. it can be Colgate,CP10023,54.50,3 where Colgate is the name, CP10023 is the product id, 54.50 is the price and 3 is the quantity. Note that the ShoppingCart object returned should have the correct totalAmount and each Item in it should the correct amount.ShoppingCart-2Modify the class ShoppingCart. Add to it the method addItem(Item item) which takes an Item as input and adds it to the field items. The way we add it is that if the customer has already added that product id to the cart earlier, only the quantity is modified and increased to reflect the new purchase. If the item was not present, then the it id added to the field items. Remember that if the field items can also be null. Also the field totalAmount should reflect the correct value.Also add the method removeItem(String productId) which takes a productId as input removes the item with that product id from the cart. Also the field totalAmount should reflect the correct value.Create the classes Section and StudentCreate a class Student which has the following fields name (of type String), marks (of type int[]), overallGrade (of type char). All the marks are out of 100, and grades are assigned on the following basis : >=85% (A grade), 70%-85% (B grade), 55%-70% (C grade), 40%-55% (D grade), prod(num2)- prod(num1>=prod(num2) and sum(num1)>sum(num2)- prod(num1)=prod(num2), sum(num1)=sum(num2), and num1>num2.bubbleSort({18,24,44,8},ascending) = {24,8,18,44}bubbleSort({33,19,91,9,133},descending) = {91,19,9,133,33}Bubble sort of strings Given an array of strings as input, sort them in ascending order using bubble sort.bubbleSort({hello,how,are,you,little,angel} = {angel,are,hello,how,little,you}Bubble Sort Large Numbers An array of String, nums, has been provided as input. Each String represents a non negative integer. The integers can be very large and hence have been stored as strings. The array has to be sorted in ascending order of the integer value of the strings.bubbleSort({999,723534,99,18456543876,54253445340001,99,112343,})={99,99,999,112343,723534,18456543876,54253445340001}Ranking students in a section Given the students of a section in a school, the objective is to order the students as per their total marks in descending order.The marks for each student are provided in the object Student, while the object Section represents all the students in the class.If two students have the same total marks, they will be ordered based on their marks in the subjects.The inputs provided are two String[]. The first String[] consists of name of student followed by his/her marks in all the subjects. The second String[] is the list of all subjects. The order of subjects in figuring out the rank in case total marks for two students are identical is the same as the order of the subjects provided in this input.The output is the object Section in which the students in Vectorhave been ordered on rank. You can download the base classes here. Also draw the class diagram for this problem.Download files for Ranking Students in a section

Module 5bSample HashtableThe download file provided is a sample of Hashtable. It adds the number names and their numbers to a hashtable and retrieves the values. It also obtains all the keys to create a hashtable where the number is the key and number name is the value. The new hashtable is then used to retrieve the number name of a specified number.Download fileDe-DuplicateGiven a String array of words as input, remove all duplicates and return a Vector of all the unique strings. Use Hashtable to solve this problem. After solving it, solve the same problem using HashSet instead of Hashtable.Max count of wordsGiven a String[] of words as input, return a Vector of most frequently occurring words. If only one word has the maximum frequency, the Vector will have a single entry. Use Hashtable to solve the problem.Same Strings (No duplicates)Given two arrays of Strings, determine if they both contain the same strings. Note that no string will appear more than once in each array. Do not use sorting to solve this problem. Also use HashSet to solve this problem.Max citiesYou have been given a Vectoras input. Each element in the vector is of type Country:City. Find out the country which has the maximum number of cities. You can assume that there is only 1 country with maximum number of cities in the input.Same Numbers , Same CountGiven two arrays of int, determine if they both contain the same numbers. Note that a number can appear more than once in each array. Also note that if a number that is present n times in the first input array, it should be present n in the second input array. And vice-versa, if a number is present m times in the second input array should be present m times in the first input array. Do not use sorting to solve this problem. Use HashMap to solve this problem.Reading Doc Understanding Java Collections FrameworkIntroductionCore Collection InterfacesAlgorithms in Collections classJavadoc : CollectionsReading Doc ExceptionsThe following are the documents to read about Exceptions.Javadoc ThrowableJavadoc ExceptionWhat is an ExceptionThe Catch or Specify RequirementCatching and Handling ExceptionsThe try BlockThe catch BlocksThe finally BlockPutting It All TogetherSpecifying the Exceptions Thrown by a MethodHow to Throw ExceptionsCreating Exception ClassesAdvantages of ExceptionsSample ExceptionsAttached is a sample code, that will provide insight into exceptions. Study and understand every concept covered in it.Sample_ExceptionShopping System This problem simulates the functioning of a department store.Product represents all the different products in the department storeProductMaster is the master of all the Product(s) in the department storeScheme represents all the schemes and offers running in the store. They have two fields, quantity and discount. Quantity represents the minimum quantity a shopper needs to purchase to qualify for the discount.ItemizedBill represents the bill of a shopperBillItem represents each line item in the ItemizedBill of the shopperBillingCounter represents all the bills that a billing counter has issued in a dayGiven the list of products, schemes and the scan details at the billing counter, process the details and return the object BillingCounter. In the scan details that have been provided as input, a bill for a shopper starts with the string START:num where num represents the id of the bill. A bill for a shopper ends with STOP.The following Java filed has been provided as download Product, ProductMaster, Scheme, BillItem, ItemizedBill and BillingCounter. Also draw the class diagram for this problem.Download files for Shopping SystemRound robin tournament A round robin soccer tournament is being played. The objective it to create the points tables based on matches played so far. Note that the points tables in sorted with the team on top coming first in the table.The input is provided as a String[] with each element consisting of 3 space demarcated values Name of team1, Name of team2 and final scoreline. The scoreline if provided as 2-1 where 2 represents the no. of goals scored by team1 and 1 represents it for team2.The object Match stores all the values for a match.The object PointsTableRow stores the performance of a particular team. It has the following fields matches played, wins, draw, loss, goalsFor (i.e. goals scored), goalsAgainst (i.e. goals the opposing team scored), points. For each win a the winning team gets 3 pts. In case of draw, both the teams get 1 point each.The Object PointsTable stores all the PointsTableRow in a vector.Note that the expected output is a PointsTable object in which the field table is sorted. The performance of two teams is compared as follows:Team A is better than Team B if A has more points than B. If points are the same, A has a better goal difference (goalsFor goalsAgainst) than B. If they are same, then A should have scored more goals than A.The following Java filed has been provided as download Match, PointsTableRow and PointsTable. Also draw the class diagrams.Download files for Round RobinReading Doc Linked ListThe following are the documents to read about Linked List.Understanding Linked ListDry Run Linked ListSampleLinkedListBasic Linked List functionsThe objective of this exercise is to implement the class BasicList1 which implements the interface ListInterface. The functions defined in ListInterface are insert, hasElement, elements and length.Note that the function getBasicList has been defined and should not be modified.Download filesBasic Linked List functions 2The objective of this exercise is to implement the class BasicList2 which implements the interface ListInterfaceAdvanced. The functions defined in ListInterface are insert, hasElement, elements, length, delete and reverse. Note that the function getBasicList has been defined and should not be modified.Download filesCount prime nodesYou have been given the head of a linked list as input. Each node of the linked list stores 2 ints, n1 and n2. Define a function that will count all those nodes from the linked list for which at least one of n1 or n2 is a prime number.Sum of neighboursYou have been given the head of a linked list as input. Each node of the linked list has 2 values of type int, myNum and sum3. The field myNum stores the value pertaining to that node. The field sum3 stores the sum of myNum for that node as well as the previous and next node. If the previous or next node is not present, it will only sum the relevant values. In the input linked list, the value of sum3 has not been computed. Define a function that will compute and assign the correct value of sum3 for each node in the linked list.Remove nodes with duplicate charsYou have been given the head of a linked list as input. Each node of the linked list stores a string data. If the field data has any char that is repeated in it, it has to removed from the list. Define a function that will remove all those nodes from the linked list for which the field data has a char that is present more than once in it.Find kth nodeYou have been given the head of a linked list and an integer k as input. Define a function which returns the kth element from the end of the input linked list in one loop only. You cannot use any collection / array. Also the input linked list should not be modified in any manner. If k is greater than the length of the linked list return null.Loop in list store node approachYou have been given the head of a linked list input. Find out whether the linked list has a loop in it or not. The approach to be used is to save all the nodes and check if you find any node that you have already saved. Solve it using vector and then solve it using HashSet.Loop in list tortoise hare approachYou have been given the head of a linked list input. Find out whether the linked list has a loop in it or not. The approach to be used is to traverse the list using two different speeds simultaneously. In traverse1 (hare) move 2 nodes at an instance, while traverse2 (tortoise) is the normal traversal. If you land on the same node in both the traversals, what does it tell you.Merge linked listsYou have been given the 2 linked lists as input. Both the linked list consist of a data of type int and are sorted in ascending order. The objective is to return a merged Linked List which is also sorted in ascending order. Note that should not create any extra node of the linked list nor use collections or arrays.

More programing exercisesNumber in words (5 digits) Given a number as input, write it as it would be written in words. Note that the number can have atmost five digits and is non-negative. Also all the characters in the output should be in lower case and a single space should be there between words.inWords(12345)= twelve thousand three hundred forty fiveinWords(0) = zeroinWords(100) = one hundredIn numerals (max 5 digits) Given a number written in words, return its equivalent numeric value. Assume that the maximum value of the number is 99999 and that it is not negative.inNumerals(sixty five thousand two hundred forty one)=65241inNumerals(four)=4Evaluate polynomial (2 variables) Given a polynomial, compute its value. The polynomial consists of 2 variables x and y and can also have a constant term in it .evalXY(-12y^2x^2-4xy-6x^4y^5+600,x=2,y=3)=-23184evalXY(x^2+y^2-4xy+2x+y+10,x=2,y=3)=6Subtract large numbers Two strings representing two numbers have been provided as input. The numbers in the string can be so large that they may not be represented by the Java datatype int. The objective is to subtract the two numbers and output it as a string. You can assume that the first number is larger than the second.< Note that "0012" is not a valid output, "12" is. Do not use BigInteger for solving this problem.Divide large numbers Two strings representing two numbers have been provided as input. The numbers in the string can be so large that they may not be represented by the Java datatype int. The objective is to divide the two numbers and output the quotient as a string. Note that 0012 is not a valid output, 12 is. Do not use BigInteger for solving this problem.Solve Expression (with multiplication)Given an arithmetic expression involving numbers and the operators +,- and * solve it. There can also be spaces in the expression which have to be ignored.solve(- 4- 12-2*12- 3-4* 5 )=-63Evaluate polynomial (n variables) Given a polynomial, compute its value. The polynomial can consist of a maximum of 20 variables and can also have constant terms in it .evalXYZ(15xyz-2x^2y^3z^4+ab+bc+abc+123,x=-2,y=-1,z=1,a=2,b=3,c=4)=203evalXYZ(a^3+d^3+f^3+m^3-100-200,a=2,d=3,f=4,m=-3)=-228Is the sum in array Given an array of positive integers and a number n as input, return true if a possible subset of elements of the array add upto n. If it is not possible return false.This problem can be solved by recursion. The key is to observe that there are only two states associated with a number. Either it will form a part of the group adding to n or it will not. Recursively evaluate if the number can lead to the sum n and also recursively evaluate if not choosing number can lead to the sum n.hasSum({2,4,8,10},14)= true (4+10 = 14)hasSum({2,3,4,8,9,10},16)= true (3+4+9 = 16)hasSum({2,4,8,10,12},15)= falseIs the sum in array (with values) Given an array of positive integers and a number n as input, return a possible subset of elements of the array that add upto n. If it is not possible return null.This problem can be solved by recursion. The key is to observe that there are only two states associated with a number. Either it will form a part of the group adding to n or it will not. Recursively evaluate if the number can lead to the sum n and also recursively evaluate if not choosing number can lead to the sum n.sumNumbers({2,4,8,10},14)={2,4,8}sumNumbers({2,4,8,10,12},15)=nullIs the sum in array (values of all solutions) Given an array of positive integers and a number n as input, return all the possible ways in which the elements of the array can add upto n. Each such possibility is returned as a String of comma(,) separated values and all the values are returned as a String[]. If it is not possible return null.This problem can be solved by recursion. The key is to observe that there are only two states associated with a number. Either it will form a part of the group adding to n or it will not. Recursively evaluate if the number can lead to the sum n and also recursively evaluate if not choosing number can lead to the sum n.allValues({2,4,8,10},14)={2,4,8,4,10}allValues({2,4,8,10,12},15)=null


Recommended