Three Strings

                                                           Three Strings

 

 

Given N string values, the program must print 3 string values as the output as described in the Example Input/Output section.
Input format:
The first line will contain N denoting the number of string values.
Next N lines will contain the N string values.
Output format:
Three lines containing string values as described in the Example Input/Output section.
Example Input/Output 1:
Input:
3
JOHN
JOHNY
JANARDHAN
Output:
JJOJAN
OHHARD
NNYHAN
Example Input/Output 2:
Input:
4
JOHN
JOHNY
JANARDHAN
MIKESPENCER
Output:
JJOJANMIKE
OHHARDSPE
NNYHANNCER

Code:

import java.util.*;
public class Hello {
    public static void main(String[] args) {
                   Scanner sc=new Scanner(System.in);
                   int n=sc.nextInt();
                   sc.nextLine();
                   int i;
                   String str[]=new String[n];
                   for(i=0;i<n;i++)
                       str[i]=sc.nextLine();
                      String p1="",p2="",p3="",ot1="",ot2="",ot3="";
                      int ctr=0;
                    for(i=0;i<n;i++)
                    {
                        int l=str[i].length();
                        ctr++;
                        int ct=l-ctr;
                        p1=str[i].substring(0,ctr);
                        p2=str[i].substring(ctr,ct);
                        p3=str[i].substring(ct,l);
                       ot1+=p1;
                       ot2+=p2;
                       ot3+=p3;
                    }
                   System.out.println(ot1);
                   System.out.println(ot2);
                   System.out.println(ot3);
          }

 

}

Check this link..

Please do comment If u have any Queries!

7 Comments

Add a Comment

Your email address will not be published. Required fields are marked *