Questions Answer

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

FindStringCode

Crazy Zak has designed the below steps which can be applied on any given string
(sentence) to produce a number.
STEP1. In each word, find the Sum of the Difference between the first letter and the last
letter, second letter and the penultimate letter, and so on till the center of the word.
STEP2. Concatenate the sums of each word to form the result.
For example –
If the given string is “WORLD WIDE WEB”
STEP1. In each word, find the Sum of the Difference between the first letter and the last
letter, second letter and the penultimate letter, and so on till the center of the word.
WORLD = [W-D]+[O-L]+[R] = [23-4]+[15-12]+[18] = [19]+[3]+[18] = [40]
WIDE = [W-E]+[I-D] = [23-5]+[9-4] = [18]+[5] = [23]
WEB = [W-B]+[E] = [23-2]+[5] = [21]+[5] = [26]
STEP2. Concatenate the sums of each word to form the result
[40] [23] [26]
[402326]
The answer (output) should be the number 402326.
NOTE1:The value of each letter is its position in the English alphabet system i.e. a=A=1,
b=B=2, c=C=3, and so on till z=Z=26.
So, the result will be the same for “WORLD WIDE WEB” or “World Wide Web” or
“world wide web” or any other combination of uppercase and lowercase letters.
IMPORTANT Note: In Step1, after subtracting the alphabets, we should use the absolute
values for calculating the sum. For instance, in the below example, both [H-O] and [E-L]
result in negative number -7, but the positive number 7 (absolute value of -7) is used for
calculating the sum of the differences.
Hello = [H-O]+[E-L]+[L] = [8-15]+[5-12]+[12] = [7]+[7]+[12] = [26]
Assumptions: The given string (sentence) will contain only alphabet characters and there
will be only one space character between any two consecutive words.
You are expected to help Zak, by writing a function that takes a string (sentence) as input,
performs the above mentioned processing on the sentence and returns the result
(number).
Example1:
input1 = “World Wide Web”
output1 = 402326
Example2:
input1 = “Hello World”
output1 = 2640
Explanation:
Hello = [H-O]+[E-L]+[L] = [8-15]+[5-12]+[12] = [7]+[7]+[12] = [26]
World = [W-D]+[O-L]+[R] = [23-4]+[15-12]+[18] = [19]+[3]+[18] = [40]
Result = Number formed by concatenating [26] and [40] = 2640
import java.util.Scanner;

public class FindStringCode{


    public static int findStringCode(String input1)
    {
        String upperCase=input1.toUpperCase();
        String str[]=upperCase.split(" ");
        String output="";
        for(int i=0;i<str.length;i++)
        {
            int sum=0;
            for(int j=0;j<str[i].length()/2;j++)
            {
                int first=str[i].charAt(j)-64;
                // System.out.println(first);
                int last=str[i].charAt(str[i].length()-1-j)-
64;
                // System.out.println(last);
                sum+=Math.abs(first-last);
                // System.out.println(sum);
            }
            if(str[i].length()%2!=0)
            {
                sum+=str[i].charAt(str[i].length()/2)-64;
            }
            output=output+sum;
        }
        return Integer.parseInt(output); 
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s=sc.nextLine();
        System.out.println(findStringCode(s));
    }
}
Get Code Through Strings:

Farah is one of the few associates in Global Safe Lockers Corp Limited, who has access
to the company’s exclusive locker that holds confidential information related to her
division. The PIN to the locker gets changed every two days. Farah receives the PIN in
the form of a string which she needs to decode to get the single-digit numeric PIN.
The numeric PIN can be obtained by adding the lengths of each word of the string to get
the total length, and then continuously adding the digits of the total length till we get a
single digit.
For example, if the string is “Wipro Technologies", the numeric PIN will be 8.
Explanation:
Length of the word “Wipro” = 5
Length of the word “Technologies” = 12
Let us add all the lengths to get the Total Length = 5 + 12 = 17
The Total Length = 17 , which is not a single-digit, so now let us continuously add all
digits till we get a single digit i.e. 1+ 7 = 8
Therefore, the single-digit numeric PIN = 8
Farah approaches you to write a program that would generate the single-digit numeric
PIN if the string is input into the program. Help Farah by writing the function (method)
that takes as input a string input1 that represents the sentence, and returns the single-digit
numeric PIN.
Assumptions: For this assignment, let us assume that the given string will always contain
more than one word.
Let's see one more example -
If the given string is "The Good The Bad and The Ugly", the numeric PIN would be = 5
Explanation:
Let us add lengths of all words to get the Total Length = 3+4+3+3+3+3+4 = 23
Total Length = 23, which is not yet a single digit, so let us continue adding all digits of
the Total Length, i.e. 2+3 = 5
Therefore, single-digit numeric PIN = 5
import java.util.Scanner;
public class GetThroughString {
    public static int SingleDigitSum(int digit)
    {
        int sum=0;
        while(digit>0||sum>9)
        {
            if(digit==0)
            {
                digit=sum;
                sum=0;
            }
            sum+=digit%10;
            digit/=10;
        }
        return sum;
    }
    public static int getCodeThroughString(String input1)
    {
        int sum=0;
        String str[]=input1.split(" ");
        for(int i=0;i<str.length;i++)
        {
            sum+=str[i].length();
        }
        // return (1+(sum-1)%9);
        return SingleDigitSum(sum);
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String str=sc.nextLine();
        System.out.println(getCodeThroughString(str));
    }
}
Addition using Strings: Write a function that takes two numbers in
string format and forms a string containing the sum (addition) of
these two numbers.
        Assumption(s):
The input strings will contain only numeric digits
The input strings can be of any large lengths
The lengths of the two input string need not be the same
The input strings will represent only positive numbers
For example –
If input strings are “1234” and “56”, the output string should be “1290”
If input strings are “56” and “1234”, the output string should be “1290”
If input strings are “123456732128989543219” and “987612673489652”, the output
string should be “123457719741663032871”
NOTE: In Java & C#, this logic can be easily implemented using BigInteger. However
for the sake of enhancing your programming skills, you are recommended to solve this
question without using BigInteger.

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;

public class AdditionUsingString {


    public static String addNumberString(String s1,String s2)
    {
        BigDecimal b1=new BigDecimal(s1);
        BigDecimal b2=new BigDecimal(s2);
        return String.valueOf(b1.add(b2));
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s1,s2;
        s1=sc.nextLine();
        s2=sc.nextLine();
        System.out.println(addNumberString(s1, s2));
    }
}
Simple Encoded Array:

Maya has stored few confidential numbers in an array (array of int). To ensure that others
do not find the numbers easily, she has applied a simple encoding.
Encoding used : Each array element has been substituted with a value that is the sum of
its original value and its succeeding element’s value.
i.e. arr[i] = original value of arr[i] + original value of arr[i+1]
e.g. value in arr[0] = original value of arr[0] + original value of arr[1]
Also note that value of last element i.e. arr[last index] remains unchanged.
For example, 
If the encoded array is {7,6,8,16,12,3}
The original array should have been {2,5,1,7,9,3}
Provided the encoded array, you are expected to find the –
First number (value in index 0) in the original array
Sum of all numbers in the original array
Write the logic in the function  findOriginalFirstAndSum(int[] input1, int input2);
where, 
input1 represents the encoded array, and 
input2 represents the number of elements in the array input1
The method is expected to –
find the value of the first number of the original array and store it in the member output1
and
find the sum of all numbers in the original array and store it in the member output2
Note that the output1 and output2 should be returned as -
- members of a Result object (if the code is being written in Java, C# or C++)
- members of a Result struct  (if the code is being written in C)
Assumption: The array elements can be positive and/or negative numbers
Example 1:
If the encoded array is {7,6,8,16,12,3}
The Original array should have been {2,5,1,7,9,3}
So, First number in original array = 2
Sum of all numbers in original array = 27
Example 2:
If the encoded array is {-2,-7,-12,-15}
The Original array should have been {8,-10,3,-15}
So, First number in original array = 8
Sum of all numbers in original array = -1
import java.util.Scanner;

class SimpleEncodedArray {
    public class Result
    {
        public final int OUTPUT1;
        public final int OUTPUT2;
        public Result(int out1,int out2)
        {
            OUTPUT1=out1;
            OUTPUT2=out2;
        }
    }
    public Result findOriginalFirstAndSum(int input1[],int
input2){
        int array[]=new int[input2];//6
        array[input2-1]=input1[input2-1];
        int sum=array[input2-1];
        for(int i=input2-2;i>=0;i--){
            array[i]=input1[i]-array[i+1];
            sum+=array[i];
        }
        Result r=new Result(array[0], sum);
        return r;
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int array[]={7,6,8,16,12,3};//6
        SimpleEncodedArray s=new SimpleEncodedArray();
        Result r=s.findOriginalFirstAndSum(array,
array.length);
        System.out.println(r.OUTPUT1);
        System.out.println(r.OUTPUT2);
    }
}
Decreasing sequence:
Given an integer array, find the number of decreasing sequences in the array and the
length of its longest decreasing sequence.
You are expected to complete the logic within the given function, 
where, 
input1 represents the integer array and,
input2 represents the number of elements in the integer array
The function should set the  output1 variable to the number of decreasing sequences in
the array, and set the  output2 variable to the length of the longest decreasing sequence in
the array.
Example 1: 
If  input1[ ] = {11,3,1,4,7,8,12,2,3,7} 
and  input2 = 10
output1 should be 2
output2 should be 3
Explanation: 
In the given array  input1, the decreasing sequences are “11,3,1” and “12,2”, i.e. there are
two decreasing sequences in the array, and so  output1 is assigned  2. The first sequence
i.e. “11,3,1” is the longer one containing  three items, when compared to the second
sequence “12,2” which contains 2 items. So, the length of the longest decreasing
sequence  output2 =  3.
Example 2: 
If  input1[ ] = {9} 
and  input2 = 1
output1 should be 0
output2 should be 0
Example 3: 
If  input1[ ] = {12,51,100,212,15,12,7,3,57,300,312,78,19,100,102,101,99,74,0,-5} 
and  input2 = 20
output1 should be 3
output2 should be 6

import java.util.Scanner;

class DecreasingSequence {
    public class Result {
        public final int OUTPUT1;
        public final int OUTPUT2;
        public Result(int out1, int out2) {
            OUTPUT1 = out1;
            OUTPUT2 = out2;
        }
    }
    public Result decreasingSeq(int input1[], int input2) {
        int decreaseCount = 0;
        int LongCount = 0;
        int SpikeCount = 0;
        boolean flag = false;
        for (int i = 0; i < input2 - 1; i++) {
            if (input1[i] > input1[i + 1]) {
                if (flag == false) {
                    flag = true;
                    SpikeCount++;
                }
                decreaseCount++;
                LongCount = decreaseCount > LongCount ?
decreaseCount : LongCount;
            }
            else
            {
                if(flag==true)
                {
                    flag=false;
                    decreaseCount=0;
                }
            }
        }
        if(SpikeCount>0)
            LongCount++;
        return new Result(SpikeCount, LongCount);
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int array[] = { 11, 3, 1, 4, 7, 8, 12, 2, 3, 7 };
        Result r=new DecreasingSequence().decreasingSeq(array,
array.length);
        System.out.println(r.OUTPUT1);
        System.out.println(r.OUTPUT2);
    }
}

Find the Most Frequently Occurring Digit in a series of numbers.

Kamal is a data analyst in a lottery management organization.


One of the tasks assigned to Kamal is to find the Most Frequently Occurring Digit in a
series of input numbers.
Below are a couple of examples to illustrate how to find the Most Frequently Occurring
Digit in a series of input numbers.
Example1 –
If the series of input numbers are [1237, 262, 666, 140]
We notice that,
0 occurs 1 time
1 occurs 2 times
2 occurs 3 times
3 occurs 1 time
4 occurs 1 time
5 occurs 0 times
6 occurs 4 times
7 occurs 1 time
8 occurs 0 times
9 occurs 0 times
We observe that –
4 is the highest frequency in this series, and,
6 is the digit that occurs 4 times.
Thus, the Most Frequently Occurring Digit in this series is 6.
NOTE: If more than one digit occur the most frequent time, then the largest of the digits
should be chosen as the answer. See below example for clarity on this point.
Example2 –
If the series of input numbers is [1237, 202, 666, 140]
We notice that,
0 occurs 2 times
1 occurs 2 times
2 occurs 3 times
3 occurs 1 time
4 occurs 1 time
5 occurs 0 times
6 occurs 3 times
7 occurs 1 time
8 occurs 0 times
9 occurs 0 times
We observe that –
3 is the highest frequency in this series, and,
2 and 6 are the digits that occur 3 times.
The larger of the two digits (2 and 6) is 6. Thus, the Most Frequently Occurring Digit in
this series is 6.
Help Kamal by writing the logic in the function mostFrequentlyOccurringDigit for
finding the Most Frequently Occurring Digit in the provided series of numbers.
The function takes two inputs - 
input1 is the array of numbers
input2 is the number of elements in the array input1

public class MostFrequencyOccuringDigitInASeriesOfNumber {


    public static int
mostFrequencyOccuringDigitInASeriesOfNumber(int input1[],int
input2)
    {
        int max=Integer.MIN_VALUE;
        int highestDigit=Integer.MIN_VALUE;
        int array[]=new int[10];
        for(int i=0;i<input2;i++)
        {
            while (input1[i]!=0) {
                array[input1[i]%10]++;
                input1[i]/=10;
            }
        }
        for(int i=0;i<array.length;i++)
        {
            if(array[i]>=max)
            {
                max=array[i];
                highestDigit=i;
            }
        }
        return highestDigit;
    }
    public static void main(String[] args) {
        int array[]={1237, 202, 666, 140}; 
System.out.println(mostFrequencyOccuringDigitInASeriesOfNumber(
array, array.length));
    }
}

Sum of Powers of Digits:

Alex has been asked by his teacher to do an assignment on powers of numbers. The
assignment requires Alex to find the sum of powers of each digit of a given number, as
per the method mentioned below.
If the given number is 582109, the Sum of Powers of Digits will be calculated as =
= (5 raised to the power of 8) + (8 raised to the power of 2) + (2 raised to the power of 1)
+ (1 raised to the power of 0) + (0 raised to the power of 9) + (9 raised to the power of 0)
i.e. each digit of the number is raised to the power of the next digit on its right-side. Note
that the right-most digit has to be raised to the power of 0. The sum of all of these powers
is the expected result to be calculated.
Example - If the given number is 582109, the Sum of Powers of Digits =
= (5 raised to the power of 8) + (8 raised to the power of 2) + (2 raised to the power of 1)
+ (1 raised to the power of 0) + (0 raised to the power of 9) + (9 raised to the power of 0)
= 390625 + 64 + 2 + 1 + 0 + 1 = 390693
Alex contacts you to help him write a program for finding the Sum of Powers of Digits
for any given number, using the above method.
Write the logic in the given function  sumOfPowerOfDigits where,
input1 represents the given number.
The function is expected to return the "Sum of Powers of Digits" of input1.
Assumptions: For this assignment, let us assume that the given number will always
contain more than 1 digit, i.e. the given number will always be >9.
import java.util.Scanner;
public class SumOfPowerOFDigits {
    public static int sumOfPowerOFDigits(int input1)
    {
        char ch[]=String.valueOf(input1).toCharArray();

        int sum=0;
        for(int i=0;i<ch.length-1;i++)
        {
            int x=Integer.parseInt(String.valueOf(ch[i]));
            int y=Integer.parseInt(String.valueOf(ch[i+1]));
            sum+=Math.pow(x, y);
        }
        return sum+
(int)Math.pow(Integer.parseInt(String.valueOf(ch[ch.length-
1])), 0);
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        System.out.println(sumOfPowerOFDigits(n));
    }
}

Sum of Sums of Digits in Cyclic order:

Alex has been asked by his teacher to do an assignment on sums of digits of a number.
The assignment requires Alex to find the sum of sums of digits of a given number, as per
the method mentioned below.
If the given number is 582109, the Sum of Sums of Digits will be calculated as =
= (5 + 8 + 2 + 1 + 0 + 9) + (8 + 2 + 1 + 0 + 9) + (2 + 1 + 0 + 9) + (1 + 0 + 9) + (0 + 9) +
(9)
= 25 + 20 + 12 + 10 + 9 + 9 = 85
Alex contacts you to help him write a program for finding the Sum of Sums of Digits for
any given number, using the above method.
Help Alex by completing the login in the given function  sumOfSumsOfDigits which
takes as input an integer input1 representing the given number.
The function is expected to return the "Sum of Sums of Digits" of input1.
Assumptions: For this assignment, let us assume that the given number will always
contain more than 1 digit, i.e. the given number will always be >9 .

import java.util.Scanner;
public class SumOfSumsOfDigitsInCyclicOrder {
    public static int sumOfSumsOfDigitsInCyclicOrder(int
input1) {
        String str = Integer.toString(input1);
        int sum = 0;
        for (int i = 0; i < str.length(); i++) {
            for (int j = i; j < str.length(); j++) {
                int num =
Character.getNumericValue(str.charAt(j));
                sum += num;
            }
        }
        return sum;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(sumOfSumsOfDigitsInCyclicOrder(n));
    }
}

Identify possible words:

Detective Bakshi while solving a case stumbled upon a letter which had many words
whose one character was missing i.e. one character in the word was replaced by an
underscore. For e.g.“Fi_er”. He also found thin strips of paper which had a group of
words separated by colons, for e.g. “Fever:filer:Filter:Fixer:fiber:fibre:tailor:offer”. He
could figure out that the word whose one character was missing was one of the possible
words from the thin strips of paper. Detective Bakshi has approached you (a computer
programmer) asking for help in identifying the possible words for each incomplete word.

You are expected to write a function to identify the set of possible words.
The function  identifyPossibleWords takes two strings as input
where, 

input1 contains the incomplete word, and


input2 is the string containing a set of words separated by colons.

The function is expected to find all the possible words from input2 that can replace the
incomplete word input1, and return the result in the format suggested below.

Example1 -

input1 = “Fi_er”
input2 = “Fever:filer:Filter:Fixer:fiber:fibre:tailor:offer”

output string should be returned as “FILER:FIXER:FIBER”


Note that –

The output string should contain the set of all possible words that can replace the
incomplete word in input1
all words in the output string should be stored in UPPER-CASE
all words in the output string should appear in the order in which they appeared in input2,
i.e. in the above example we have FILER followed by FIXER followed by FIBER.
While searching for input1 in input2, the case of the letters are ignored, i.e “Fi_er”
matches with “filer” as well as “Fixer” as well as “fiber”.
IMPORTANT: If none of the words in input2 are possible candidates to replace input1,
the output string should contain the string “ERROR-009”

Assumption(s):
Input1 will contain only a single word with only 1 character replaced by an underscore
“_”
Input2 will contain a series of words separated by colons and NO space character in
between
Input2 will NOT contain any other special character other than underscore and alphabetic
characters.
import java.io.*;
import  java.util.*;
class UserMainCode
{
    public String identifyPossibleWords(String input1,String
input2){
        String output="";
        String array[]=input2.split(":");
        int index=input1.indexOf("_");
        for(int i=0;i<array.length;i++)
        {
            if(array[i].length()==input1.length())
            {
                String test1=array[i].toUpperCase();
                char ch[]=test1.toCharArray();
                ch[index]='_';
                test1=String.valueOf(ch);
                String test2=input1.toUpperCase();
                if(test2.equals(test1))
                {
                    if(output=="")
                    {
                        output+=array[i].toUpperCase();
                    }
                    else
                    {
                        output+=":"+array[i].toUpperCase();
                    }
                }
            }
        }
        if(output=="")
        {
            output="ERROR-009";
        }
        return output;
    }
}
public class IdentifyPossibleWords
{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        UserMainCode um=new UserMainCode();
        System.out.println(um.identifyPossibleWords("Fi_er",
"Fever:filer:Filter:Fixer:fiber:fibre:tailor:offer"));
    }
}

Encoding Three Strings:

Anand was assigned the task of coming up with an encoding mechanism for any given
three strings. He has come up with the below plan.
STEP ONE: Given any three strings, break each string into 3 parts each.
For example – If the three strings are as below -
Input1= “John”
Input2= “Johny”
Input3= “Janardhan”
“John” should be split into “J”, “oh”, “n” as the FRONT, MIDDLE and END parts
respectively.
 “Johny” should be split into “Jo”, “h”, “ny” as the FRONT, MIDDLE and END parts
respectively.
“Janardhan” should be split into “Jan”, “ard”, “han” as the FRONT, MIDDLE and END
parts respectively.
i.e. if the no. of characters in the string are in multiples of 3, then each split-part will
contain equal no. of characters, as seen in the example of “Janardhan”
If the no. of characters in the string are NOT in multiples of 3, and if there is one
character more than multiple of 3, then the middle part will get the extra character, as
seen in the example of “John”
If the no. of characters in the string are NOT in multiples of 3, and if there are two
characters more than multiple of 3, then the FRONT and END parts will get one extra
character each, as seen in the example of “Johny”
STEP TWO:  Concatenate (join) the FRONT, MIDDLE and END parts of the strings as
per the below specified concatenation-rule to form three Output strings.
Output1 = FRONT part of Input1 + FRONT part of Input2 + FRONT part of Input3
Output2 = MIDDLE part of Input1 + MIDDLE part of Input2 + MIDDLE part of Input3
Output3 = END part of Input1 + END part of Input2 + END part of Input3
For example, for the above specified example input strings,
Output1 = “J” + “Jo” + “Jan” = “JJoJan”
Output2 = “oh” + “h” + “ard” = “ohhard”
Output3 = “n” + “ny” + “han” = “nnyhan”
Step THREE: After the first two steps, we will have three output strings. Further
processing is required only for the third output string as per below rule –
“ Toggle the case of each character in the string”, i.e. in the third output string, all lower-
case characters should be made upper-case and vice versa.
For example, for the above example strings, Output3 is “nnyhan”, so after applying the
toggle rule, Output3 should become “NNYHAN”.
Final Result – The three output strings after applying the above three steps is the final
result. i.e. for the above example,
Output1 = “JJoJan”
Output2 = “ohhard”
Output3 = “NNYHAN”
Anand approaches you to help him write a program that would do the above mentioned
processing on any given three strings and generate the resulting three output strings
Note that the three output strings should be returned as members of a "Result"
object/struct.

import java.io.*;
import java.util.*;
// Read only region start
class UserMainCode {

    public class Result {


        public final String output1;
        public final String output2;
        public final String output3;
        public Result(String out1, String out2, String out3) {
            output1 = out1;
            output2 = out2;
            output3 = out3;
        }
    }

    public Result encodeThreeStrings(String input1, String


input2, String input3) {
       
        String array1[] = new String[3];
        String array2[] = new String[3];
        String array3[] = new String[3];

        array1 = getparts(input1);
        array2 = getparts(input2);
        array3 = getparts(input3);

        String output1 = "";


        String output2 = "";

        output1 = array1[0] + array2[0] + array3[0];


        output2 = array1[1] + array2[1] + array3[1];
        StringBuilder output3 = new StringBuilder(array1[2] +
array2[2] + array3[2]);

        for (int i = 0; i < output3.length(); i++) {


            if (Character.isUpperCase(output3.charAt(i))) {
                output3.setCharAt(i,
Character.toLowerCase(output3.charAt(i)));
            } else {
                output3.setCharAt(i,
Character.toUpperCase(output3.charAt(i)));
            }
        }
        return new Result(output1, output2,
output3.toString());

    }

    public static String[] getparts(String inputs) {


        int len = inputs.length();
        String parts[] = new String[3];
        int partLen = len / 3;
        // case-1: 9/3=3
        // case-2: 4/3=1
        // case-3: 5/3=1

        System.out.println("str : " + inputs + "Len : " + len


+ "partLen : " + partLen);

        if (len % 3 == 0) {
            parts[0] = inputs.substring(0, partLen);
            parts[1] = inputs.substring(partLen, 2 * partLen);
            parts[2] = inputs.substring(2 * partLen, len);
            System.out.println("For case-1 :" + parts[0] + " "
+ parts[1] + " " + parts[2]);
        }
        if (len % 3 == 1) {
            parts[0] = inputs.substring(0, partLen);
            parts[1] = inputs.substring(partLen, 2 * partLen +
1);
            parts[2] = inputs.substring(2 * partLen + 1, len);
            System.out.println("For case-2 :" + parts[0] + " "
+ parts[1] + " " + parts[2]);
        }
        if (len % 3 == 2) {
            parts[0] = inputs.substring(0, partLen + 1);
            parts[1] = inputs.substring(partLen + 1, 2 *
partLen + 1);
            parts[2] = inputs.substring(2 * partLen + 1, len);
            System.out.println("For case-2 :" + parts[0] + " "
+ parts[1] + " " + parts[2]);
        }
        return parts;
    }
}
public class EncodingThreeStrings {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String input1=sc.nextLine();
        String input2=sc.nextLine();
        String input3=sc.nextLine();
        UserMainCode um=new UserMainCode();
        System.out.println("OutPut1 : "+
um.encodeThreeStrings(input1, input2, input3).output1);
        System.out.println("OutPut2 :
"+um.encodeThreeStrings(input1, input2, input3).output2);
        System.out.println("OutPut3 :
"+um.encodeThreeStrings(input1, input2, input3).output3);
    }
}

You might also like