Tag Archives: Java - Page 2

Lexicographic Order in Java

Lexicographic Order Problem Write java method to compare two strings lexicographically. The method should return 0 if the two strings are Lexicographically equal. It should return 1 if the first string comes before the second string in the dictionary. It …

Read more »

Java Replace String Function

Problem Write a Java method to replace a sub string in a given text with another string of the same size Solution Loop through the text character by character. Starting at the current character loop a number of times equal …

Read more »

Ternary Search Tree Java

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 …

Read more »

String to Long

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 …

Read more »

Line Intersection

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 …

Read more »

Array shuffle Java

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 …

Read more »

Number of Iterations

Problem If you run the following block of java code. How many times the print statement is going to execute. public class Counting { public static void main(String[] args)   {   for (int i = 0; i < 100; …

Read more »

Page 2 of 3123