FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaTutorial/src/F022_SimplifyingIfStatements.java at master · windweb/JavaTutorial · GitHub
windweb
/
JavaTutorial
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaTutorial
/
src
/
F022_SimplifyingIfStatements.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (31 loc) · 1.33 KB
Breadcrumbs
JavaTutorial
/
src
/
F022_SimplifyingIfStatements.java
Copy path
File metadata and controls
40 lines (31 loc) · 1.33 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
public
class
F022_SimplifyingIfStatements
{
public
static
void
main
(
String
[]
args
) {
int
income1
=
120_000
;
if
(
income1
>
100_000
) {
boolean
hasHighIncome1
=
true
;
}
// System.out.println(hasHighIncome1);
// ошибка компиляции, так как несмотря на то, что переменная hasHighIncome1
// объявлена внутри блока if,
// но к ней нет доступа вне блока if
// чтобы решить эту проблему можем сделать следующее:
int
income2
=
120_000
;
boolean
hasHighIncome2
;
if
(
income2
>
100_000
)
hasHighIncome2
=
true
;
else
hasHighIncome2
=
false
;
System
.
out
.
println
(
hasHighIncome2
);
// но код выше - выглядит не оптимальным.
// Вот как его можно оптимизировать
int
income3
=
120_000
;
boolean
hasHighIncome3
=
false
;
if
(
income3
>
100_000
)
hasHighIncome3
=
true
;
System
.
out
.
println
(
hasHighIncome3
);
// можно ещё оптимизировать код
int
income4
=
120_000
;
boolean
hasHighIncome4
= (
income4
>
100_000
);
System
.
out
.
println
(
hasHighIncome4
);
}
}
Back
|
FazBrowse Home
|
New Git URL