DEV Community

Cover image for Zensar Technologies Assessment question Coding 1 & 2
Gourav Kadu
Gourav Kadu

Posted on

31 2

Zensar Technologies Assessment question Coding 1 & 2

First

Given an email address extract username U by eliminating the "@" and subsequent character to form a new string and add length of U at the end of the string to be formed .
Read Sample input output for better understanding.

Input1:

gourav.mk@gmail.com
Enter fullscreen mode Exit fullscreen mode

Output1:

gourav.mk9
Enter fullscreen mode Exit fullscreen mode

Input2:

hellofrankyji@gmail.com
Enter fullscreen mode Exit fullscreen mode

Output:

hellofrankyji13
Enter fullscreen mode Exit fullscreen mode

Solution:

  • Paste the sample input in STDIN to check the code
  • To Tinker the code click here
import java.io.*;
import java.util.*;
public class TestClass {
    public static void Extraction(String Str){
        String sep = "@";
        int pos = Str.lastIndexOf(sep);
        String input = Str.substring(0,pos);
        int len = input.length();
        System.out.print(input+""+len);
    }

    public static void main(String args[]) {
   Scanner sc = new Scanner(System.in);
   String Str = sc.nextLine();
   Extraction(Str);
    }
}
Enter fullscreen mode Exit fullscreen mode

Second

Given two integer A and B, write a program to print binary equivalent N of the GCD(greatest common divisor) of A and V and also print the number of 1s in N.
Read the Sample input output to understand better.

Input1:

20 100
Enter fullscreen mode Exit fullscreen mode

Output1:

10100
2
Enter fullscreen mode Exit fullscreen mode

Explanation 1:

*will be updated soon *

Solution:

import java.util.*;
public class TestClass {
    static int findgcd(int x, int y){
        int gcd = 1;
        for(int i = 1 ; i<=x && x<=y ; i++){
            if(x%i == 0 && y%i==0){
                gcd = i;
            }
        }
        return gcd;
    }
    public static String binaryString(int n){
        String b="";
        b = Integer.toBinaryString(n);

        return b;
    }
    public static int numberOfOnes(String b){
        int count =0;
        for(int i =0; i < b.length();i++){
            if(b.charAt(i)=='1'){
            count++;}
        }
        return count;
    }
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int x= sc.nextInt();
        int y= sc.nextInt();
    String b = binaryString(findgcd(x,y));
    System.out.println(b);
    System.out.print(numberOfOnes(b));

    }
}
Enter fullscreen mode Exit fullscreen mode

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs