
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

























int cadence = 0; anArray[0] = 100; System.out.println("Element 1 at index 0: " + anArray[0]); int result = 1 + 2; System.out.println(x == y? "equal" :"not equal");
if (x == 2) System.out.println("x is 2"); System.out.println("Finished"); if x == 2 : print "x is 2" print "Finished"
Notes about Java’s if-‐then :
if(x == 2) { System.out.println("even"); System.out.println("prime"); } System.out.println("Done!"); Note:
if(age >= 18) { boolean adult = true; } /* couldn't use adult here */
if(x < y) { System.out.println("x < y"); } else if (x > y) { System.out.println("x > y"); } else { System.out.println("x == y"); } if x < y: print "x < y" elif x > y: print "x > y" else: print "x == y"
switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: System.out.println("31 days"); break; case 4: case 6: case 9: case 11: System.out.println("30 days"); break; case 2: System.out.println("28 or 29 days"); break; default: System.err.println("Invalid month!"); break; } Notes:
int count = 0; while(count < 10) { System.out.println(count); count++; } System.out.println("Done!"); count = 0 ; while(count < 10 ): print count count += 1 print "Done!"
for (initialization; termination; increment) { /* ... statement(s) ... */ }
for(int count = 0; count < 10; count++) { System.out.println(count); } System.out.println("Done!"); for count in range( 0 , 10 ): print count print "Done!"
String[] items = new String[]{"foo","bar","baz"}; for(int i = 0; i < items.length; i++) { System.out.printf("%d: %s%n", i, items[i]); } items = ["foo", "bar", "baz"] for i in range(len(items)): print "%d: %s" % (i, items[i])
for (