COMP202CribSheetFinal

COMP202CribSheetFinal - COMP 202 Open Crib Sheet brought to...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
COMP 202 Open Crib Sheet - brought to you by McGill Open Courses (now with twice the Z or R) FYI: NEVER GONNA GIVE YOU UP. NEVER GONNA LET YOU DOWN. NEVER GONNA RUN AROUND AND DESERT YOU. CODE SNIPPETS Useful code fragments public class  NameofFile  { public objectName(parameters) {  // constructor for Objects public static void main(String[] args) {   // main method, args commonly used, can be another  name <access modifier> <return type> <method name>(parameters) { // general format for other methods public int divide(int dividend, int divisor) {     // example import java.util.Scanner; / import java.util.PrintStream; / import java.io.IOException; / import  java.io.File; Scanner keyboard = new Scanner(System.in);   // put in main method for keyboard input variable = keyboard.nextType();      // type can be Int, Double, Float, Char or any primitive  type variable = keyboard.nextLine();  // no nextString, use nextLine which moves cursor  to next line Scanner fileReader = new Scanner(File path);     // put in main method for file reading fileReader.close();   // scanner must be closed after file reading is complete PrintStream writer = new PrintStream(File output);      //don’t forget  import.java.util.PrintStream; variableType[] arrayName = new variableType[SIZE];      // 1D array declaration and allocation variableType[][] arrayName = new variableType[columnSize][rowSize];  // 2D array declaration and  allocation while (condition) {  // while loop, infinite loop if always true, increment with count++ or use other  boolean for ({initialize}; {condition}; {increment}) { // for loop, use instead of while if known amount of  iterations
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/22/2011 for the course COMP 202 taught by Professor Verbrugge during the Fall '07 term at McGill.

Page1 / 3

COMP202CribSheetFinal - COMP 202 Open Crib Sheet brought to...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online