FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/day21/code/java/ForTest2.java at master · szmas/Java · GitHub
szmas
/
Java
Public
forked from
DuGuQiuBai/Java
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Java
/
day21
/
code
/
java
/
ForTest2.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (27 loc) · 648 Bytes
Breadcrumbs
Java
/
day21
/
code
/
java
/
ForTest2.java
Copy path
File metadata and controls
34 lines (27 loc) · 648 Bytes
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
/*
需求:求出1-10之间数据之和
0+1=1
1+2=3
3+3=6
6+4=10
10+5=15
...
因为每一次的累加结果都是变化的,所以要定义一个变量,专门用于记录每次累加的结果。
由于我们需要的1,2,3,4...也是变化的,所以我们也要定义一个变量,而这个变量用循环就能得到每个值。
*/
class
ForTest2
{
public
static
void
main
(
String
[]
args
) {
//最好想
//System.out.println(1+2+3+4+5+6+7+8+9+10);
//跟循环结合起来
int
sum
=
0
;
for
(
int
x
=
1
;
x
<=
10
;
x
++) {
//x=1,2,3,4,...10
//sum = sum + x; //sum=0 + 1 = 1;
//sum = sum + x; //sum=1 + 2 = 3;
//sum = sum + x;
sum
+=
x
;
}
System
.
out
.
println
(
"1-10的和是:"
+
sum
);
}
}
Back
|
FazBrowse Home
|
New Git URL