Programming challenges I use to hire Programmers

Whenever I hire programmers, I prefer to give them programming tasks within the interview, or before coming to the interview. I thought that I might share this with fellow CEans, I generally use problems from Project Euler as programming challenges.

For.e.g #1 Multiples of 3 or 5 - Project Euler

This is the simplest problem there. Check out some of the other problems, it is the perfect test for comp. sci. engineers, since not only does this test your logic writing skills but also it tests your knowledge of your favorite programming language!!

Replies

  • K!r@nS!ngu
    K!r@nS!ngu
    Java code:


    public class Add
    {
    public static void main(String[] args)
    {
    int sum=0;
    int num = 0;
    System.out.println("This Java program will add all the natural numbers below one thousand that are multiples of 3 or 5.");
    while(num<999)
    {
    num++;
    if(num%3 == 0 || num%5 == 0)
    {
    sum=sum+num;
    }
    }
    System.out.println("Sum is: "+ sum);
    }
    }


    I like these kind of programming tasks. can you give more ?
  • vinci
    vinci
    nice puzzle .how can we do this-
    write any number-
    2
    you wrote-two

    in java ??How is this possible i still dont know
  • K!r@nS!ngu
    K!r@nS!ngu
    vinci
    nice puzzle .how can we do this-
    write any number-
    2
    you wrote-two

    in java ??How is this possible i still dont know

    It's simple. we have to create a scanner object and take input. Re-printing the number pretty easy 😀 Let me try and give the code.
  • K!r@nS!ngu
    K!r@nS!ngu
    Here is the code:

    import java.util.Scanner;
    public class Number
    {
    public static void main(String args[])
    {
    Scanner input=new Scanner(System.in);
    int number;
    System.out.print( "Enter any number: " );
    number=input.nextInt();
    System.out.printf( "You have entered:%d ",number );
    }
    }
  • vinci
    vinci
    i think you didnt understood the whole puzzle i posted.When user enters integers,its output must be in words.like if i enter 100,so output must be "one hundred"
  • K!r@nS!ngu
    K!r@nS!ngu
    vinci
    i think you didnt understood the whole puzzle i posted.When user enters integers,its output must be in words.like if i enter 100,so output must be "one hundred"
    Oops..😕 let me give a one more trail....
  • K!r@nS!ngu
    K!r@nS!ngu
    Bro. Finally got it after taking help from Google.
    Concept is simple:
    1. Analyzing the input(counting no. of digits).
    2. Converting to string based on no. of digits in the input.
    Code is :

    import java.lang.*;
    import java.io.*;
    import java.util.*;
    class constNumtoLetter{
    String[] unitdo ={"", " One", " Two", " Three", " Four", " Five",
    " Six", " Seven", " Eight", " Nine", " Ten", " Eleven", " Twelve",
    " Thirteen", " Fourteen", " Fifteen", " Sixteen", " Seventeen",
    " Eighteen", " Nineteen"};
    String[] tens = {"", "Ten", " Twenty", " Thirty", " Forty", " Fifty",
    " Sixty", " Seventy", " Eighty"," Ninety"};
    String[] digit = {"", " Hundred", " Thousand", " Lakh", " Crore"};
    int r;
    //Count the number of digits in the input number
    int numberCount(int num){
    int cnt=0;
    while (num>0){
    r = num%10;
    cnt++;
    num = num / 10;
    }
    return cnt;
    }
    //Function for Conversion of two digit
    String twonum(int numq){
    int numr, nq;
    String ltr="";
    nq = numq / 10;
    numr = numq % 10;
    if (numq>19){
    ltr=ltr+tens[nq]+unitdo[numr];
    }
    else{
    ltr = ltr+unitdo[numq];
    }
    return ltr;
    }
    //Function for Conversion of three digit
    String threenum(int numq){
    int numr, nq;
    String ltr = "";
    nq = numq / 100;
    numr = numq % 100;
    if (numr == 0){
    ltr = ltr + unitdo[nq]+digit[1];
    }
    else{
    ltr = ltr +unitdo[nq]+digit[1]+" and"+twonum(numr);
    }
    return ltr;
    }
    }
    class ActiveMQSwing{
    public static void main(String[] args){
    try
    {
    //Defining variables q is quotient, r is remainder
    int len, q=0, r=0;
    String ltr = " ";
    String Str = "You have entered";
    constNumtoLetter n = new constNumtoLetter();
    System.out.println("Enter number");
    Scanner input=new Scanner(System.in);
    int num = input.nextInt();
    if (num <= 0)
    System.out.println("Zero or Negative number not for conversion");
    while (num>0){
    len = n.numberCount(num);
    //Take the length of the number and do letter conversion
    switch (len){
    case 8:
    q=num/10000000;
    r=num%10000000;
    ltr = n.twonum(q);
    Str = Str+ltr+n.digit[4];
    num = r;
    break;
    case 7:
    case 6:
    q=num/100000;
    r=num%100000;
    ltr = n.twonum(q);
    Str = Str+ltr+n.digit[3];
    num = r;
    break;
    case 5:
    case 4:
    q=num/1000;
    r=num%1000;
    ltr = n.twonum(q);
    Str= Str+ltr+n.digit[2];
    num = r;
    break;
    case 3:
    if (len == 3)
    r = num;
    ltr = n.threenum(r);
    Str = Str + ltr;
    num = 0;
    break;
    case 2:
    ltr = n.twonum(num);
    Str = Str + ltr;
    num=0;
    break;
    case 1:
    Str = Str + n.unitdo[num];
    num=0;
    break;
    default:
    num=0;
    System.out.println("Exceeding Crore....No conversion");
    System.exit(1);
    }
    if (num==0)
    System.out.println(Str+" ");
    }
    }
    catch(Exception e)
    {
    System.out.print(e);
    }
    }
    }
    
    op
  • vinci
    vinci
    hmm this one is what i was searching since long.Thanks for the help .you solved my query .

You are reading an archived discussion.

Related Posts

1.At 8 p.m., Vaigai Express from Madurai and The Chennai Express from Chennai are moving in opposite direction at 40 km/hr and 60 km/hr. At Trichy, they meet each other....
German engineers have crafted a device that can hear sound with intensity as low as -60dB. It means if bacteria were to talk, you can hear their voices. The team...
In the future, you could charge your cell phone just by chatting Researchers at South Korea’s Sungkyunkwan University have developed a new technology that converts soundwaves into electrical energy, The...
Consider a Tree, whose every parent node can have N child nodes. It's easy to store in structures during the execution of program For that I've implemented Linked Lists. But...
Is it possibile to transmit Electrical Energy without wire ? If yes then in which stage the research is?