Tag: Java

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 code in Java //Main class public class String2Long { //Main function public static void main(String

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 Cartesian plane so we can use 4 private variables for that. For the intersection we

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 the following restrictions: 1. Arrange the array in place i.e. do not use any additional