1 / 12

Midterm Review Highlights and Key Concepts in Java Programming

This document summarizes key concepts and important reminders for the upcoming midterm exam in Java programming. Topics include instantiating objects, using packages, assignment operators, loop equivalence, and nested if statements. Examples are provided to clarify these concepts, ensuring students understand how to implement them in their code. Additionally, the review emphasizes the relationships between different loop types and offers practice scenarios to reinforce learning. Prepare for the exam with these targeted insights and practice exercises.

Télécharger la présentation

Midterm Review Highlights and Key Concepts in Java Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMP 14: Midterm Review June 8, 2000 Nick Vallidis

  2. Announcements • Midterm is tomorrow!

  3. Assignment P4 • Just want to go over it to make sure you all understand...

  4. Instantiating objects • We do this with the keyword new • Examples: String name; name = new String("Vallidis"); Die myDie; myDie = new Die(6);

  5. packages • A 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 • All loops have the same four parts: • initialization • condition • statements (the loop body) • increment (the loop update -- it doesn't have to be an increment specifically) • As a result, you can convert between loop types.

  8. Equivalence of loops for (initialization; conditon; update) body; initialization; initialization; while (condition) do { { body; body; update; update; } } while (condition);

  9. Nested if statements • What's up with this? if (x < 3) if (y > 2) System.out.println("yay!"); else System.out.println("x >= 3");

  10. Nested if statements • write nested ifs to do the following: • you have one integer x • when 0<=x<5 print "low" • when 5<=x<10 print "medium" • when 10<=x<15 print "high" • for any other value of x don't do anything ------------------------------------------------------ • Can you do this as a switch statement?

  11. nested loops • what 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 • Write 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;

More Related