/* *
* to calculate the sum of 1-100, the odd and even number and
*/
Public class sum100 {
Public static void main (String [] args) {
Int I=1;
Int sum=0; Total//
Int sumOdd=0;//odd and
Int sumOushu=0;//the even and
while (i<{
=100)
The sum +=I;//sum=sum + I
If (I % 2==0) {
//even
SumOushu +=I;
} else {
//odd
SumOdd +=I;
}
}
i++;
}
System. The out. Println (" the sum of 1-100: "+ sum);
System. The out. Println (" the sum of 1-100: "+ sumOdd);
System. The out. Println (" the sum of 1-100: "+ sumOushu);
}
an error is as follows:
Error: (29, 23) Java: need & lt; Identifier & gt;
Error: (29, 25) Java: the type of illegal start
Error: (30, 23) Java: need & lt; Identifier & gt;
Error: (30, 24) Java: the type of illegal start
Error: (31, 23) Java: need & lt; Identifier & gt;
Error: (31, 24) Java: the type of illegal start
CodePudding user response:
Your output statements on the outside, techniques, and should be in the main methodYou can under an ide to help you learn so that you know there is something wrong with the place
CodePudding user response:
Public class sum100 {Public static void main (String [] args) {
Int I=1;
Int sum=0; Total//
Int sumOdd=0;//odd and
Int sumOushu=0;//the even and
while (i<{
=100)
The sum +=I;//sum=sum + I
If (I % 2==0) {
//even
SumOushu +=I;
} else {
//odd
SumOdd +=I;
}
i++; //
in a loop}
//on cycle inside the
System. Out. Println (" the sum of 1-100: "+ sum);
System. The out. Println (" the sum of 1-100: "+ sumOdd);
System. The out. Println (" the sum of 1-100: "+ sumOushu);
}
}
CodePudding user response:
Even if you use a notepad also won't make this mistakeCodePudding user response:
Thank you for your eldest brother, the basic fault, no patience to review, thank youCodePudding user response: