My collection of things.

jKafer on the Net

February 15th, 2012 at 5:52 pm

Show your work!!!!!

During a recent job interview, I was given a programming test / quiz – which I botched up royally – I froze. And no, I didn’t get the job. So in the spirit of my math teachers – I’m going to ‘Show My Work’.

The test was to write the code to display numbers 1-100, if divisible by 3 – write “Yeah”, if divisible by 5 – write “Baby”, if divisible by both – “Yeah Baby”. I didn’t freeze because I didn’t know how to do the “for/while” statements/loop or the “if” statements, it was because I had never had to check for a WHOLE number before. So my mind was racing on a small detail of the question – in my mind an important part of the question (but not to them I guess). Well, I now know how to check for a whole number in 3 different ways. Something learned!!!

So here are my 3 versions (I have a tendency to be dramatic you know):

JavaScript:

<script type="text/javascript">
function YB(){
    for(i=1;i<=100;i++)
    {
        x = i/3;
        y = i/5;
        if(x == parseInt(x)){
            a = " Yeah";
        }
        if (y == parseInt(y)){
            a = a+ " Baby";
        }

        document.write(i+" "+a+" <br />");
        a = "";
    }
}

</script>

PHP:

for ($i =1; $i<=100; $i++)
{
    if($i % 3 == 0){
        $a = " Yeah";
    }
    if($i % 5 == 0){
        $a .= " Baby";
    }
    print $i." ".$a."<br />";
    $a = "";
}

Java:

public class yeahBaby{
    public static void main(String[] args) {
        for(double i =1; i <= 100; i=i+1)
        {
            String a = "";
            double x = i/3;
            double y = i/5;
            if(x == Math.rint(x)){
                a = " Yeah";
            }
            if(y == Math.rint(y)){
                a = a+ " Baby";
            }
            System.out.println(Math.round(i)+" "+a);
        }
    }
}

-

Comments are closed.


  • Pages

  • Latest Pins on Pinterest

    • Follow Me on Pinterest

  • Quilting Projects I Want to Make

    • quilt kits black and gray - Google Search

    • How To Make A Quillow. One of my aunts made me one as a high school graduation gift. I wore it out and miss it!

    • Cute Cathedral Window by Pitter Putter Stitch. I'm really wanting to try the cathedral window quilt block and this one is so so pretty!

    • How about a modern I Spy quilt? This pattern uses a total of 51- 5" I Spy squares in the following colors: ...

    • Usando os presentes fofos !

    • My pdf patterns  are available  for purchase from my online Etsy shop here . Wholesale printed patterns are only available directly from m...

    • Arrowhead Quilt PDF Pattern — Initial K Studio

    • Dimension designed by Nydia Kehnle. Features #konacotton. Pattern available for purchase (nydiakehnle.bigca...).

    • Follow Me on Pinterest