Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI S-1 Section 4. 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.

Similar presentations


Presentation on theme: "CSCI S-1 Section 4. 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."— Presentation transcript:

1 CSCI S-1 Section 4

2 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

3 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.

4 Primitive Types int double char boolean byte short long float integers: 42, -3 real numbers: 7.35 single characters: ‘a’, ‘X’ logical values: true, false 8-bit integer 16-bit integer 64-bit integer 32-bit real (6-7 digits precision)

5 Operator Precedence (in decreasing order) Unary operators Multiplicative operators Additive operators Assignment operators +-+- */%*/% +-+- =+=-=*= /=%= =-5 + (4* (3/2)) -1 = 0 =-(5 + 6 - 1) = -10 - 5 + 4 * 3 / 2 - 1 - (5 + 4 * 3 / 2 - 1)

6 For Loops //Syntax: for (counter= initial_value; logical condition for continuation; update counter) { } //Sequence: //Initialize – Test – Execute Code Block – Update //Example: for( int i=0; i < 5; i++ ) { System.out.println(“i= “ + i); }

7 Constants class Section4a { public static void main(String [] args) { final int NUMBER_OF_LINES = 10; for(int i = 1; i <= NUMBER_OF_LINES; i++) { System.out.println("HELLO"); } System.out.println ( i );// what’s wrong here? }

8 Nested For Loops class Section4b { public static void main(String [] args) { for(int i=0; i < 5; i++ ) { System.out.println(“i= ” + i); for (int j=0; j<=i; j++) System.out.println(“\tj = ” + j); }

9 Type Matters class Section4c { public static void main(String [] args) { int result = 2; for(int i = 1; i <= 5; i++) { result =* result; System.out.println("Result = " + result); } System.out.println("Result = " + result); } // Output is 0. Why?

10 XPowerN // Write a program that computes X to the power of N, where both X and N are // constants that the user can initialize before compiling the program class Section4d { }

11 XPowerN // Write a program that computes X to the power of N, where both X and N are // constants that the user can initialize before compiling the program class Section4d { public static void main(String [] args) { final int N = 3; final int X = 5; int result = 1; for (int i = 1; i <= N; i++) result*= X; System.out.println("The result is: " + result); }


Download ppt "CSCI S-1 Section 4. 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."

Similar presentations


Ads by Google