GIGO: words unreadable aloud
Mishrogo Weedapeval
 

 

  Wednesday 12 May 2004
Chapter 3, Exercise 9, Thinking in Scala

Integer.parseInt is from java.lang.Integer. I guess i could have used the "tfor" loop that I defined here, if I wanted this to look more like Java or more like what the exercise statement was asking for.

object c3x9 {
    def main ( args: Array[String] ) = {
        val limit = Integer.parseInt( args(0) );
        var cand = 2;
        while (cand < limit) {
            var is_prime = true;
            var test = 2;
            while (is_prime  &&  test*test <= cand ) {
                if ( (cand % test) == 0 ) {
                    is_prime= false;
                }
                else {
                    test = test +1;
                }
            } 
            if (is_prime)
                Console.println( cand + " is prime." );
            /*
            else
                Console.println( cand + " is not prime." );
            */ 
            cand = cand +1;
        }
    }
}

8:13:31 AM   comment/     


Click here to visit the Radio UserLand website. Click to see the XML version of this web page. © Copyright 2007 Doug Landauer .
Last update: 07/2/6; 12:39:26 .
Click here to send an email to the editor of this weblog.

May 2004
Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Apr   Jun

Previous/Next