CSCI S-1 Section 3
Deadlines for Homework 2 Problems 1-8 in Parts C and D – Friday, July 3, 17:00 EST Parts E and F – Tuesday, July 7, 17:00 EST
Connecting to your FAS account (nice.fas.harvard.edu) Mac OS: Terminal – Windows: SecureCRT – Downloads site –
Getting around in Linux Listing files Changing directories Making directories Removing directories Removing files Copying files Moving files Print file to monitor Your present working directory ls cd mkdir rmdir rm cp mv cat pwd
Using Nano To edit a textfile – nano filename Inside nano – control+O to save – control+X to exit – additional commands explained in the help at the bottom of the screen.
Submitting Homework Setup your account by running ~libs1/pub/bin/s1setup Execute the logout command by typing logout and then enter Login again and make a directory to hold all of your homework – mkdir s1 Get into s1 – cd s1 Make a directory for parts C, D (ps21) and E, F (ps22) – mkdir ps21 – mkdir ps22 Test-drive the submit tool by submitting a temporary part 1 – s1submit ps21 NB: Your last submission is the one timestamped and graded.
Java Exercises Type up this simple program in nano and save it as section3.java class section3 { public static void main(String [] args) { System.out.println("Hello!"); } Compile it: javac section3.java Run it:java section3
Java Exercises Write a java program that will print the following H E L L O \ \ _ "." JAVA Programming class section3a { public static void main(String [] args) { System.out.println("H E L L O\\\\_ \".\""); System.out.println("JAVA"); System.out.println("Programming"); } }
Java Exercises Rewrite the program using one method to print each line class section3b { static void firstLine() { System.out.println("H E L L O\\\\_ \".\""); } static void secondLine() { System.out.println("JAVA"); } … public static void main(String [] args) { firstLine(); secondLine(); thirdLine(); } }
Understanding Variable Scope class section3c { static int x, y, z; static void first() { int x, y;x = 0; y = 1; System.out.println("x = " + x + ", y = " + y + " z = " + z); } static void second() { int z;y = 7; z = 1; System.out.println("x = " + x + ", y = " + y + " z = " + z); } static void third() { int y;x = 7; y = 1; System.out.println("x = " + x + ", y = " + y + " z = " + z); } public static void main(String [] args) { x = 2; y = 2; z = 3; first(); second(); third(); }
Understanding Variable Scope (cont) class section3c { … public static void main(String [] args) { x = 2; y = 2; z = 3; System.out.println("x = " + x + ", y = " + y + " z = " + z); first(); second(); third(); System.out.println("x = " + x + ", y = " + y + " z = " + z); } x = 2, y = 2 z = 3 x = 0, y = 1 z = 3 x = 2, y = 7 z = 1 x = 7, y = 1 z = 3 x = 7, y = 7 z = 3