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.


  • Count per Day

    • 4Visitors today:
    • 40Visitors per day:
    • 0Visitors currently online:
  • ScrapBook Software - MyMemoriesSuite
  • Latest Pins on Pinterest

    • Blue Carolina Starburst Quilt {Free Pattern}

    • Well Texas Tumbleweeds got finished.  If you missed that, find it here.  So it’s time for a new UFO.  Earlier I had pulled Fair and Square but after I got the string triangles done, I left it…

    • 719 Likes, 25 Comments - David (@scfdavid) on Instagram: “Here’s my Blockheads block for Week 45 - Double Dutch - from my friend, Jo Morton! Thanks, Jo! All…”

    • Quilt patriotic Hidden Glorry reserved for Carrie by marytequilts

    • Tutorial - How to Get Perfect Centers

    • How to sew and trim half rectangle triangles (HRTs) - Kirsty of Bonjour Quilts

    • Center Point designed by Elise Lea for Robert Kaufman. Features Chalk and Charcoal by Jennifer Sampou, shipping to stores May 2018. Roll up friendly. FREE pattern available for download from robertkaufman.com May 2018. #FREEatrobertkaufmandotcom

    • A modern quilt blog focused on practical tutorials and quilting tips. Sharing traditionally pieced quilt patterns and lots of free quilt alongs.