parseInt - Spot the Errors


Goal:

Write the following snippets on the whiteboard and ask students to fix the errors.

Steps:

  1. Have students take turns and tell them to only fix ONE mistake so everyone gets plenty of turns.
  2. Ask students not to erase the original code, just put a line through an error and write their suggestion above. That way if the fix is not correct, another student can still see the original.

    Snippet 1:
    String repeat = JOptionPain.showInput("How many students are there?");
    
    int numRepeats = Integer.parse(repeat);
    
    for(int i; i > repeat; i++) {
          System.print.out (student + numRepeats) 
    }
    


    Snippet 2:
    String answer = JOptionPane.showInputDialog("How many bottles?" );
    
    int bottles = integer.passInt(bottles);
    
    for ( i=bottles; i < 0; i++ ) {
          JOptionPane.showMessageDialog(nil, i "green bottles hanging on the wall/n Crash!!!!" );
    }
    
    JOptionPane.showMassageDialog(nil, "There's a lot of broken glass out here!" );