Difference between revisions of "212 Homework 2 Solutions 2014"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- </onlydft> =Homework #2 Solution Programs= ==Problem #1== ===PythonList.java=== <br /> <source lang="java"> /** * PythonList.java * @author D. Thiebaut * A crud...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
--[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 10:16, 26 September 2014 (EDT)
 
--[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 10:16, 26 September 2014 (EDT)
 
----
 
----
</onlydft>
+
<onlydft>
 
=Homework #2 Solution Programs=
 
=Homework #2 Solution Programs=
 
==Problem #1==
 
==Problem #1==
Line 178: Line 178:
 
</source>
 
</source>
 
<br />
 
<br />
/**
 
  * Computes the 9th row of Pascal's triangle.
 
  * @author D. Thiebaut
 
  */
 
public class PascalList {
 
    static private final int ROW = 9;
 
  
    /**
 
    * Constructor. (Not really needed in this program, but could in more complex application.)
 
    */
 
    public PascalList() {
 
       
 
    }
 
  
    static public void main( String[] args ) {
 
        PythonList row = new PythonList( 3 );
 
        row.append( 1 );
 
        for ( int i=1; i<ROW; i++ )
 
            row.append( 0 );
 
               
 
        for ( int i=1; i<ROW; i++ ) {
 
            for ( int k=ROW-1; k>0; k-- )
 
                row.setAt(k,  row.at(k-1) + row.at(k) );
 
        }
 
        for ( int i=0; i<row.length(); i++ )
 
            System.out.println( row.at(i) + " " );
 
        System.out.println();
 
    }
 
}
 
  
</onlydft>
 
 
==Problem #2==
 
==Problem #2==
 
<br />
 
<br />
Line 325: Line 297:
  
 
</source>
 
</source>
<br /><br />
+
<br />
 +
</onlydft>
 +
<br />
 
<br /><br /><br />
 
<br /><br /><br />
 
<br /><br /><br />
 
<br /><br /><br />

Latest revision as of 09:18, 26 September 2014

--D. Thiebaut (talk) 10:16, 26 September 2014 (EDT)



...