Home > Back-end >  New to JAVA practice first program error, consult everybody eldest brother
New to JAVA practice first program error, consult everybody eldest brother

Time:09-24

program is as follows:

/* *
* 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 method
You 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 mistake

CodePudding user response:

Thank you for your eldest brother, the basic fault, no patience to review, thank you

CodePudding user response:

reference Prinary_ reply: 3/f
even if you use notepad also can't make the wrong
know, thank you

CodePudding user response:

refer to the second floor usecf 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);

}

}
thank you
  • Related