Home > Back-end >  Java small white recently self-study Java want to ask the code of it
Java small white recently self-study Java want to ask the code of it

Time:11-29

Public class Happy
{
Public static void main (String [] args)

{
int count=0;
for(int i=1; i<=5; I++)
{
The count=count + I;
System. The out. Println (" I="+ I +" "+" count="+ count);

}

}
}
The results I=1 count=1
I=2 count=3
I=3 count=6
I=4 count=10
I=5 count=15
Want to ask what meaning is the + I + and the final count result is how to calculate the 1 3 6 10 15 of these results

CodePudding user response:

Can a detailed answers? Thank

CodePudding user response:

reference 1st floor czh010527 response:
can please detailed answers to appreciate


This is a for loop, I initial value is 1, each loop I + 1, until I jump out of the cycle, after more than five

+ here is the link identifier of the string, "I=" + I + "" +" count="+ count, double quotes here are strings, I and the count will be automatically converted to a string, and then by + link together,

By the count=count + I; This sentence to accumulate
The first cycle count=I=1 0
So the count=0 + 1=1
The 2nd cycle I=2 count=1
So count=1 + 2=3
,,, and so on,


CodePudding user response:

The right hand side of the count's record as I - 1 in front of the accumulation of numerical,
So the count to the left of the equals sign is the first time I cumulative values, for 1 + 2 + 3 + 4 +... +i

CodePudding user response:

+ I + + is the string concatenation, I is to display the I current value

CodePudding user response:

Looking for a book, you are so white

CodePudding user response:

+ I + refers to the value I will print it out, the count value is through the calculation of the for loop, the first cycle, before I has a value of 1, the count as the initial value of 0, + I will count is 1 the result of the assignment to the count, the count value into 1, then I and count the value of the printed, end of the first cycle; Before the second cycle, since I value plus 1, into 2, less than or equal to 5, continue to cycle, when the count value is 1, plus two equals three, assigned to count and print the,,, the value of the loop until I do not conform to the less than or equal to 5, 6, end of the cycle, I equal to 6 do not conform to the conditions, so don't need to print

CodePudding user response:

Is this two + number + I + used for string concatenation

CodePudding user response:

Do you want to learn I can teach you

CodePudding user response:

You that portal, https://how2j.cn/, the Java learning materials with system inside,

CodePudding user response:

What do you mean the + I + and finally the count result is how to calculate the 1 3 6 10 15 of these results:

CodePudding user response:

+ I + what's the meaning of this and the last the count result is how to calculate the 15 of these results: 1 3 6 to 10 + I + see before and after the content of the first, this is a process of string concatenation, "I=" + I + "" +" count="+ count , is colored your variables, count=count + I; This is you to calculate the logic of the count, in a loop for the first time to 0 + 1=1, 1 + 2=3, 3 + 3=6, 6 + 4=10, 10 + 5=15, one in front of the figure is before the count value, after a number with the value of the I, so the count result is calculated as 1 3 6 10 to 15

CodePudding user response:

"I="
+
I
+
"
"+
"Count="
+
Count
String concatenation, when I=1 output like this: I=1 count=1;
Recommend that you add a breakpoint to debug,
  • Related