Replica Asked Coding Question with Detailed Solution 2021 | Hiring for Software Engineer Trainee Role | Rs 5.5 LPA | Live Now

Replica Asked Coding Question with Detailed Solution 2021 | Hiring for Software Engineer Trainee Role | Rs 5.5 LPA | Live Now

Replica Asked Coding Question with Detailed Solution 2021 | Hiring for Software Engineer Trainee Role | Rs 5.5 LPA | Live Now

6 MCQ + 2Coding Questions 

*same for everyone*

MCQ answers -

(might get jumbled )

  • 1. 5
  • 2. 30
  • 3. 16
  • 4. Sample
  • 5. 4
  • 6. error at line 5


Coding Answer -


1. HOW MANY WORDS -

//code for HOW MANY WORDS...

//It's poorly written code but it's working perfectly fine 👍

import java.util.*;

public class Main

{

 public static void main(String args[])

 {

  String str = "";


      Scanner scan = new Scanner(System. in); //remove space before in

 str = scan.nextLine();

  

  int length = str.length();

  

  int count = 0;

  boolean flag = false;

  boolean invalid = false;

  

  for(int i=0;i<length;i++)

  {

   char c = str.charAt(i);

   

   if( !(((c>='a' && c<='z') || (c>='A' && c<='Z') || c=='-') ||  c==' ' || c == '.' || c=='?' || c==',' || c=='!') && !invalid)

   {

    invalid = true;

   }

   

   else if( (c==' ' || c == '.' || c=='?' || c==',' || c=='!') && invalid )

   {

    invalid = false;

    flag = false;

   }

   else if(!invalid)

   {

    if( (c==' ' || c == '.' || c=='?' || c==',' || c=='!') && flag )

    { 

     count += 1;

     flag = false;

    }

    else if( ( (c>='a' && c<='z') || (c>='A' && c<='Z') ) && !flag  )

     flag = true;

   }

  }  

  

  System.out.println(count);  

  

 }  


}


2. SIMPLE CIPHER answer


#only test cases are passed, due to some internal fault hidden test cases are showing 'runtime error occurred


import java.util.*;


public class Main

{

 public static void main(String args[])

 {


     Scanner scan = new Scanner(System. in);


  String encr = scan.nextLine();

  int k = scan.nextInt();

  

  int length = encr.length();

  

  String out = "";

  

  if(k>26) k %= 26;

  

  for(int i=0; i<length;i++)

  {

   char c = encr.charAt(i);

   

       c = (char)(c-k);


   if( c < 'A')

    c = (char)(c+26);


       out += c;

  } 

  

  System.out.println(out);  

  

 }

}


Have Any Query Ask Here

Comments