00000000000George Kocur

00000000000George Kocur - 1.00 Lecture 3 Operators, Control...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1.00 Lecture 3 Operators, Control Reading for next time: Big Java: sections 6.1-6.4 Skip all the advanced topics, hints, etc. Main() About main(): In each Java program there is a just a single main() method, no matter how many classes there are. The main() method is often in a class that has no other methods, by convention. It can be in any class, though some choices would seem unnatural. main() tells Java where to start the program; it’s just a naming convention It could easily have been called “StartHere” In early examples we have only one class, so it will seem there’s a main() method in each class. Nope. Main() at a later point will be minimalist: Main() does the least possible work to get the program running and then hands off all the remaining work to objects and their methods. For now, since we haven’t covered classes and objects, we’ll do everything in main() for a little while longer.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Logical Operators Produce results of type boolean Comparisons use 9 operators: Equal == Not equal != Less than < Less than or equal <= Greater than > Greater than or equal >= Logical and && Logical or || Not ! // Example int c= 0, b= 3; if (c != 0 && b/c > 5) System.out.println(“Buy this stock”); // Short circuit evaluation: quit after answer determined boolean buy= true; if (!buy || c == 0) System.out.println(“Nah, don’t buy”); Assignment Operators Assignment is not the same as equality = is not the same as == Assignments are expressions: int x, y; x= y= 5; // Same as x = (y= 5); assoc from R to L Shortcut forms exist: int x= 5, y= 3; x += y; // Same as x= x + y; // This means take current value of x (5), add y (3), and // set x to a new value of 8 Shortcut forms include +=, -=, *=, /=, %= : x /= y; // Same as x= x / y; x %= y; // Same as x= x % y; Other shortcut forms are ++ and -- : x++; // Same as x= x + 1; y= --x; // Same as x= x-1; y = x; (More later)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

00000000000George Kocur - 1.00 Lecture 3 Operators, Control...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online