CSC300: Lists/Arrays [9/12] Previous pageContentsNext page

PythonJava
01
02
03
04
05
06
07
08
09
10
def myprint(a):
    for x in a:
        print(x)

def main():
    lst = [11,21,31]
    myprint(lst)

if __name__ == "__main__":
    main()
01
02
03
04
05
06
07
08
09
10
11
12
13
package algs11;
import stdlib.*;
public class Hello {
  public static void myPrint (double[] a) {
    for (double x : a) {
       StdOut.println(x);
    }
  }
  public static void main (String[] args) {
    double[] lst = { 11, 21, 31 };
    myPrint (lst);
  }
}
PythonJava
01
02
03
04
05
06
07
08
09
10
def myprint(a):
    for i in range(len(a)):
        print(i, a[i])

def main():
    lst = [11,21,31]
    myprint(lst)

if __name__ == "__main__":
    main()
01
02
03
04
05
06
07
08
09
10
11
12
13
package algs11;
import stdlib.*;
public class Hello {
  public static void myPrint (double[] a) {
    for (int i=0; i<a.length; i++) {
       StdOut.println(i + " " + a[i]);
    }
  }
  public static void main (String[] args) {
    double[] lst = { 11, 21, 31 };
    myPrint (lst);
  }
}
PythonJava
01
02
03
04
05
06
07
08
09
10
def myprint(a):
    for i,x in enumerate(a):
        print(i, x)

def main():
    lst = [11,21,31]
    myprint(lst)

if __name__ == "__main__":
    main()
01
02
03
04
05
06
07
08
09
10
11
12
13
14
package algs11;
import stdlib.*;
public class Hello {
  public static void myPrint (double[] a) {
    for (int i=0; i<a.length; i++) {
       double x = a[i];
       StdOut.println(i + " " + x);
    }
  }
  public static void main (String[] args) {
    double[] lst = { 11, 21, 31 };
    myPrint (lst);
  }
}

Previous pageContentsNext page