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
Output1:
gourav.mk9
Input2:
hellofrankyji@gmail.com
Output:
hellofrankyji13
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);
    }
}
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
Output1:
10100
2
Explanation 1:
*will be updated soon *
Solution:
- Paste the sample input in STDIN to check the code
- To Tinker the code [click here].(https://www.jdoodle.com/a/40oN)
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));
    }
}
 
 
              
 
    
Top comments (0)