Presentation is loading. Please wait.

Presentation is loading. Please wait.

Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.

Similar presentations


Presentation on theme: "Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data."— Presentation transcript:

1 Review Review Review

2 Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data type: –Byte, short, int, long, float, double –Char, boolean –String

3 Concepts Assignment statement Boolean expressions Identifiers, constants Commands: –If –Switch –Do/While, While, and For

4 Concepts File extension: *.java, *.class Compile: Textpad: Compile Java and Run java DOS: javac and java

5 Project 1 (Section 01) Average: 93.14 (35 students submitted)

6 Project 1 (Section 2) Average: 97 (only 28 students submitted)

7 Lab section

8 Homework 1 (Section 01) Avg =84.3. Max = 99.

9 Homework 1 (Section 02) Avg = 88, Max = 100

10 Rules for Midterm exam -Student ID is required - Don’t: -Leave the exam room after the exam is distributed -Use cell phone or computers (PC) - Talk with each other during the exam - Limit of questions you can ask teacher during exam time. If you ask more than two questions, you will have some points off taken from your exam.

11 Answers to Homework 1 1. In general, commands to compile and execute a java program are a. compile and run b. compile and link c. javac and java d. java and link This is the only answer accepted if this question is asked in another exam

12 Homework 1 - Answer 2. All Java program must have this method to run a. hello() b. start() c. main() d. method()

13 Homework 1 3. Which of the following is not mandatory in variable declaration a. a semicolon b. an assignment c. a variable name d. a data type

14 Homework1 4. You store java source code files with following extension? a..java b..class c..src d..javadoc

15 Homework1 5. A single line comment in Java starts with a. ; b. # c., d. // e. none of the above

16 Homework1 6. Java language is case sensitive a. True b. False

17 Homework1 7. As long as a computer has a Java Virtual Machine, the same program written in the Java programming language can run on any computer a. True b. False

18 Homework1 8. Which of the following is an invalid identifier? a. one b. Two c. _3Four d. 4Five

19 Homework1 9. Which of the following is an invalid variable declaration? a. String inputStr; b. int i=0; c. boolean flag = true; d. double, int, j=0;

20 Homework1 10. Assuming the following declarations are executed in sequence, why are the second and the third declarations invalid? int a,b; double a; double b; a. Both a and b are invalid identifiers. b. Variable a has been declared c. Variable b has been declared d. Both variables a and b have been declared in the first declaration

21 Homework1 11. The __new_____operator is used to create a new object

22 Homework 1 12. Identifiers may not start with a ___number (digit)________ or contain__special/(non-alpha- numeric)_____characters, other than the underscore or the dollar sign

23 Homework 1 13. char data type represents individual _character______

24 Homework 1 14. Text data can be stored in _String__objects

25 Homework 1 15. Constants __can not be (never be, are not)__changed during program execution

26 Homework 1 16. Boolean expressions are built by use of _relational___operators and _boolean__________operators

27 Homework 1 17. Every variable that we use in a Java program must be _declared/defined__________

28 Homework 1 18. A Java program is composed of one or more ___classes__

29 Homework 1 20. int a== b; == can’t be used in variable declaration

30 Homework 1 21. double monthlyInterestRate; if (monthlyInterestRate >= 0.08) && (monthlyInterestRate <= 0.5 ); { System.out.println(“Interest rate is invalid”); System.exit(1); } 1.() is needed or remove )( before and after && 2.; should be take out 3.No value has been initialized for monthlyInterestRate

31 Homework 1 22. char userChoice=’l’; if (userChoice ==’s’) { System.out.print(“ Drop small cup into position”); (1) Missing ; } else{ System.out.println(“ Drop large cup into position”); } else System.exit(-1); 2. { should be inserted here Else should be taken out

32 Homework 1 23. String choice=”5”; switch(choice) { case 4: System.out.println(“ Right branch”); break; default: System.out.println(“ Default branch”); break; } 1. Switch doesn’t support String data type. It must be char or int(bytes,short,int)

33 Homework 1 24. int sum=0; for (int i=0, i< 100);{ sum+= i; } 1; int i=0, this comma should be semicolon 2. Missing post body update (increment or decrement) 3. semicolon after 100) should be taken out

34 Homework 1 25. int x,y; x=-10; y=-20; if ( y>0 && x< y) System.out.println(" The output is "+(x+y)); else System.out.println(" The output is "+(x-y)); The output is 10 (Because -10-(-20) = -10+20 = 10)

35 Homework 1 26. int count=0, sum=0; while (count < 10) { sum += count; count+=3; } System.out.println(" Sum ="+ sum); count=0sum =0 count = 3sum = 0+3=3 count = 6sum = 3+6=9 count = 9sum = 9+9=18

36 Homework 1 27. int nextToPrint = 1; int maximum = 10; while(nextToPrint <= maximum){ if (nextToPrint % 2 != 0) System.out.print(nextToPrint+" "); nextToPrint = nextToPrint +1; } System.out.println(); 1 3 5 7 9

37 Homework 1 28. int sum=0; int i=0; while (i<5) { int j=4; while (i!=j) { sum += j; j=j-1; } i++; } System.out.println(" Sum ="+sum); Sum = 30

38 Homework 1 sum=0i=0 j=4 sum = 0+4 = 4 j=3 sum = 4+3 = 7 j=2 sum = 7+2 = 9 j=1 sum = 9+1=10

39 Homework 1 i=1 j=4 sum = 10+4 = 14 j=3 sum = 14+3 = 17 j=2 sum = 17+2 = 19

40 Homework 1 i=2 j=4 sum = 19+4 = 23 j=3 sum = 23+3 = 26

41 Homework 1 i=3 j=4 sum = 26+4 = 30


Download ppt "Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data."

Similar presentations


Ads by Google