Problem Write a java program to construct and print a ternary Tree. A ternary tree is similar to a binary tree except a parent node can have up to three children instead of two. The left child value is less than the parent value, the right is greater than the parent value and the middle
Problem Write a java program to convert a character string into long data type. Solution We have already solved this problem using C++ in the post String to Integer. The code below shows a java implementation. Code Here is the code in Java
Problem Design a simple Java class to implement the concept of a line in the Cartesian plane. Provide a method to test if the line intersects with another line. Solution Two points are enough to define a line in the Cartesian plane so we can use 4 private variables for that. For the intersection we
Array shuffle algorithm Given an array of 2n integers in the following format a1 a2 a3 … an b1 b2 b3 … bn. Rearrange the array as follows a1 b1 a2 b2 a3 b3 … an bn taking into consideration the following restrictions: 1. Arrange the array in place i.e. do not use any additional
Problem If you run the following block of java code. How many times the print statement is going to execute. Solution You can modify the code by adding a counter then let the code itself calculates how many times it executes however that is not what the problem is all about. You can trace the
Problem Write a Java program to find character counts in a string consisting from capital letters (A to Z) only. The program must not use nested loops. Hash tables that are built in to the language must not be used as well. For example if the input string is “CACBACDDDD” the output of the program
Problem Write a Java class to implement a stack data structure using an array for storage. The stack must support pop and push operations. Java stack implementation A stack is a LIFO (last in first out) data structure. A push operation adds an element to the top of the stack. On the other hand a