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

Comments /* . . . */ - multi line comment // . . . - single-line comment /** . . . */ - comment for documentation. It

Слайд 12. Java Basics
2. Java Statements


Слайд 2Comments
/* . . . */ - multi line comment
// .

. . - single-line comment
/** . . . */ - comment for documentation. It can include some additional tags (e.g. @version, @author, @param, @return).

*

Infopulse Training Center


Слайд 3How 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

*

Infopulse Training Center


Слайд 4Variables
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.

*

Infopulse Training Center


Слайд 51. 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);
}
}

*

Infopulse Training Center


Слайд 62. 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);
}
}
}

*

Infopulse Training Center


Слайд 73. 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);
}
}

*

Infopulse Training Center


Слайд 84. 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);
}
}
}

*

Infopulse Training Center


Слайд 9Constant Declaration
final modifier: final int a = 42;

// a = 12; - compile error

*

Infopulse Training Center


Слайд 10If-Then_Else Statement I
if (boolean_expression) {
statements
}

if (boolean_expression) {
statements
} else {
statements
}
*
Infopulse

Training Center

Слайд 11If-Then_Else Statement II
if (boolean_expression) {
statements;
} else if (boolean_expression) {
statements;
} else if

(boolean_expression) {
statements;
}

*

Infopulse Training Center


Слайд 12If-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");
}

*

Infopulse Training Center


Слайд 13Switch Statement
switch(integral-expression) {
case integer-value1 :
statements;
case integer-value2

:
statements;
break;

case integer-value3 :
statements;
break;

default:
statements;
}

*

Infopulse Training Center


Слайд 14Switch Example
char c = ’b’;
switch(c) {
case ’a’:
case ’e’:
case

’i’:
case ’o’:
case ’u’:
print("vowel");
break;

case ‘y’:
case ‘w’:
print("Sometimes a vowel");
break;
default:
print("consonant");
}

*

Infopulse Training Center


Слайд 15Switch 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!)

*

Infopulse Training Center


Слайд 16While and Do-While Statement
while (boolean_expression) {
statements;
}

do {
statements;
}

while (boolean_expression);

*

Infopulse Training Center


Слайд 17While Example
double a = 100.;
while (a >= 1) {

System.out.println(a);
a /= 2.;
}

*

Infopulse Training Center


Слайд 18Do-While Example
double a = 0.5;
do {
System.out.println(a);

a /= 2.;
} while (a >= 1);

*

Infopulse Training Center


Слайд 19For Statement
for (initialization; Boolean-expression; step) {
statements;
}
*
Infopulse Training Center


Слайд 20For 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);

*

Infopulse Training Center


Слайд 21Break 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

*

Infopulse Training Center


Слайд 22Use Break with a Label
L: for … {

for…{
break L;
}
}

*

Infopulse Training Center


Слайд 23Exercise 2.2.1.
Find and print all divisors of a given natural number

n.

*

Infopulse Training Center


Слайд 24Exercise 2.2.1.
See 221Divisors project for the full text.

*
Infopulse Training Center


Слайд 25Exercise 2.2.2.
Find and print all prime divisors of a given natural

number n.

*

Infopulse Training Center


Слайд 26Exercise 2.2.3.
Find sum of an infinite row for a given x


Compare

result with a Math.exp(x) method value

*

Infopulse Training Center


Слайд 27Manuals
Learning the Java Language. Language Basics
*
Infopulse Training Center


Обратная связь

Если не удалось найти и скачать презентацию, Вы можете заказать его на нашем сайте. Мы постараемся найти нужный Вам материал и отправим по электронной почте. Не стесняйтесь обращаться к нам, если у вас возникли вопросы или пожелания:

Email: Нажмите что бы посмотреть 

Что такое ThePresentation.ru?

Это сайт презентаций, докладов, проектов, шаблонов в формате PowerPoint. Мы помогаем школьникам, студентам, учителям, преподавателям хранить и обмениваться учебными материалами с другими пользователями.


Для правообладателей

Яндекс.Метрика