2. Java Basics. Java Statements презентация

Содержание


Презентации» Информатика» 2. Java Basics. Java Statements
2. Java Basics
 2. Java StatementsComments
 /* . . . */ - multi line comment 
How to Use Comments
 Comments should be used to give overviewsVariables
 Variables declaration: int k;
      1. What will this program output?
 public class InitTest {
 2. What will this program output?
 public class Oblzm {
 3. What will this program output?
 public class Oblzm {
 4. What will this program output?
 public class Oblzm {
 Constant Declaration
 final modifier: final int a = 42;
  If-Then_Else Statement I
 if (boolean_expression) {
   statements
 }
 ifIf-Then_Else Statement II
 if (boolean_expression) {
 	statements;
 } else if (boolean_expression)If-Then-Else Example
 int a = 10;
 if (a > 0) {
Switch Statement
 switch(integral-expression) { 
 case integer-value1 : 
  Switch Example
 char c = ’b’;
 switch(c) { 
 case ’a’:Switch Statement Expressions
 You can use enumerations as switch expression andWhile and Do-While Statement
 while (boolean_expression) {
   statements;
 }
While Example
 double a = 100.;
  while (a >= 1)Do-While Example
 double a = 0.5;
  do {
  For Statement
 for (initialization; Boolean-expression; step) {
   statements;
 }For Examples
 for (int i = 10, k = 20; iBreak and Continue Statements
 break quits the loop without executing theUse Break with a Label
 L: for … {
  Exercise 2.2.1.
 Find and print all divisors of a given naturalExercise 2.2.1.
 See 221Divisors project for the full text.Exercise 2.2.2.
 Find and print all prime divisors of a givenExercise 2.2.3.
 Find sum of an infinite row for a givenManuals
 Learning the Java Language. Language Basics



Слайды и текст этой презентации
Слайд 1
Описание слайда:
2. Java Basics 2. Java Statements


Слайд 2
Описание слайда:
Comments /* . . . */ - multi line comment // . . . - single-line comment /** . . . */ - comment for documentation. It can include some additional tags (e.g. @version, @author, @param, @return).

Слайд 3
Описание слайда:
How to Use Comments Comments should be used to give overviews of code and provide additional information that is not readily available in the code itself Comments should contain only information that is relevant to reading and understanding the program Doc comments describe Java classes, interfaces, constructors, methods, and fields Java associates documentation comments with the first declaration after the comment

Слайд 4
Описание слайда:
Variables Variables declaration: int k; double x = 2.1; Local variable should be initialized before it will be used. Variable scope is a block where it was declared. Sub block can’t contain duplicated variable declaration.

Слайд 5
Описание слайда:
1. What will this program output? public class InitTest { public static void main (String[] args) { int a = 5; int b; if (a < 0) b = 10; if (a >= 0) b = 50 ; System.out.println(b); } }

Слайд 6
Описание слайда:
2. What will this program output? public class Oblzm { public static void main (String args[]){ int i = 5; { int j = 2; System.out.println("Result is " + i * j); } } }

Слайд 7
Описание слайда:
3. What will this program output? public class Oblzm { public static void main (String args[]){ int i = 5; { int j = 2; } System.out.println("Result is “ + i * j); } }

Слайд 8
Описание слайда:
4. What will this program output? public class Oblzm { public static void main (String args[]){ int i = 5; { int j = 2; int i = 4; System.out.println("Result is " + i * j); } } }

Слайд 9
Описание слайда:
Constant Declaration final modifier: final int a = 42; // a = 12; - compile error

Слайд 10
Описание слайда:
If-Then_Else Statement I if (boolean_expression) { statements } if (boolean_expression) { statements } else { statements }

Слайд 11
Описание слайда:
If-Then_Else Statement II if (boolean_expression) { statements; } else if (boolean_expression) { statements; } else if (boolean_expression) { statements; }

Слайд 12
Описание слайда:
If-Then-Else Example int a = 10; if (a > 0) { System.out.println("Positive"); } else if (a < 0) { System.out.println("Negative"); } else { System.out.println("Zero"); }

Слайд 13
Описание слайда:
Switch Statement switch(integral-expression) { case integer-value1 : statements; case integer-value2 : statements; break; case integer-value3 : statements; break; default: statements; }

Слайд 14
Описание слайда:
Switch Example char c = ’b’; switch(c) { case ’a’: case ’e’: case ’i’: case ’o’: case ’u’: print("vowel"); break;

Слайд 15
Описание слайда:
Switch Statement Expressions You can use enumerations as switch expression and case values You can use strings as switch expression and case values (since Java 7 only!)

Слайд 16
Описание слайда:
While and Do-While Statement while (boolean_expression) { statements; } do { statements; } while (boolean_expression);

Слайд 17
Описание слайда:
While Example double a = 100.; while (a >= 1) { System.out.println(a); a /= 2.; }

Слайд 18
Описание слайда:
Do-While Example double a = 0.5; do { System.out.println(a); a /= 2.; } while (a >= 1);

Слайд 19
Описание слайда:
For Statement for (initialization; Boolean-expression; step) { statements; }

Слайд 20
Описание слайда:
For Examples for (int i = 10, k = 20; i < k; i++, k--) { System.out.println(i + " " + k); } for (char i = 's'; i >= 'b'; i--) System.out.println(i);

Слайд 21
Описание слайда:
Break and Continue Statements break quits the loop without executing the rest of the statements in the loop. continue stops the execution of the current iteration and goes back to the beginning of the loop to begin the next iteration. You can use a label before an iteration statement and in break / continue statements interrupt the loops up to where the label exists

Слайд 22
Описание слайда:
Use Break with a Label L: for … { for…{ break L; } }

Слайд 23
Описание слайда:
Exercise 2.2.1. Find and print all divisors of a given natural number n.

Слайд 24
Описание слайда:
Exercise 2.2.1. See 221Divisors project for the full text.

Слайд 25
Описание слайда:
Exercise 2.2.2. Find and print all prime divisors of a given natural number n.

Слайд 26
Описание слайда:
Exercise 2.2.3. Find sum of an infinite row for a given x Compare result with a Math.exp(x) method value

Слайд 27
Описание слайда:
Manuals Learning the Java Language. Language Basics


Скачать презентацию на тему 2. Java Basics. Java Statements можно ниже:

Похожие презентации