Find LCM of two numbers using GCD in java (example)

LCM (Least common multiple) of two integers is the least positive integer that is divisible by both a and b. e.g  lcm(10,15) = 30 or lcm(12,18) = 36. LCM is also referred as  lowest common multiple or smallest common multiple. LCM can be calculated by calculating the GCD (greatest common divisor) of two positive integer. Example:… Read More »

Reverse each word of a string using StringBuilder in java (example)

Given a string in java, reverse each word of string using StringBuilder in java. Let us look into couple of examples to understand problem statement. Example 1: String inputString = “live star war” reverse(inputString) should be “evil rats raw” Example 2: String inputString = “live desserts” reverse(inputString) should be “evil stressed” Algorithm: reverse each word… Read More »

Reverse string word by word in java (stack/ stringbuilder /example)

Given a string in java, reverse the string word by word. Let us look into couple of examples to understand problem statement. Example 1: String inputString = “Girl Proposes Boy” reverse(inputString) should be “Boy Proposes Girl” Example 2: String inputString = “Hell To Heaven” reverse(inputString) should be “Heaven To Hell” 1. Algorithm: Reverse string word… Read More »

Page 10 of 42« First...89101112...203040...Last »