Download presentation
Presentation is loading. Please wait.
1
COMP 14: Midterm Review June 8, 2000 Nick Vallidis
2
Announcements zMidterm is tomorrow!
3
Assignment P4 zJust want to go over it to make sure you all understand...
4
Instantiating objects We do this with the keyword new zExamples: String name; name = new String("Vallidis"); Die myDie; myDie = new Die(6);
5
packages zA package is a group of classes That's it. In Java, each class has its own.java file and all the.java files in a directory are one package.
6
Assignment operators mult += value is just the same thing as: mult = mult + value This is just a shortcut so you don't have to type mult twice! You can replace + with any of the normal math operators: -, /, %, etc.
7
Equivalence of loops zAll loops have the same four parts: yinitialization ycondition ystatements (the loop body) yincrement (the loop update -- it doesn't have to be an increment specifically) zAs a result, you can convert between loop types.
8
Equivalence of loops for (initialization; conditon; update) body;initialization; while (condition)do{body;update;} while (condition);
9
Nested if statements zWhat's up with this? if (x < 3) if (y > 2) System.out.println("yay!"); else System.out.println("x >= 3");
10
Nested if statements zwrite nested ifs to do the following: yyou have one integer x ywhen 0<=x<5 print "low" ywhen 5<=x<10 print "medium" ywhen 10<=x<15 print "high" yfor any other value of x don't do anything ------------------------------------------------------ zCan you do this as a switch statement?
11
nested loops zwhat does this code do? int i, j; for (i=1; i<=5; i++) { for (j=i; j>=1; j--) System.out.print("*"); System.out.println(); }
12
nested loops zWrite code to print out a person's name 5 times and then ask if they want to do it again. If they do, then print their name again 5 times (response can be string or integer) Assume the name has already been read and has this declaration: String name;
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.