When you use a variable named static today:
package com.day7.demo4;
public class Pengue {
String name;
String sex;
int love=0;
int health=60;
static final String SEX_MALE = "Q-boy";
static final String SEX_FEMALE = "Q-girl";
public Pengue() {
super();
}
public Pengue(String name, String sex, int love, int health) {
super();
this.name = name;
this.sex = sex;
this.love = love;
this.health = health;
}
public void print() {
System.out.println("name:"+name+",sex:"+sex+",intimacy:"+love+",Health:"+health);
}
}
For Penguetest.java, go ahead:
System.out.print("Please select the sex of your Penguin:(1.boy 2.girl)");
int num = sc.nextInt();
if (num == 1) {
Pengue.SEX_MALE;
}else if (num ==2) {
Pengue.SEX_FEMALE;
}
The error is as follows:
Syntax error, insert "VariableDeclarators" to complete LocalVariableDeclaration
It is correct after modification as follows:
System.out.print("Please select the sex of your Penguin:(1.boy 2.girl)");
int num = sc.nextInt();
if (num == 1) {
pengue.sex = Pengue.SEX_MALE;
}else if (num ==2) {
pengue.sex = Pengue.SEX_FEMALE;
}
Assign it to a variable, because that’s the same thing as 1; Because SEX_MALE is now constant, avoid this error in the future;
Read More:
- Syntax error, insert “;” to complete Statement, insert “}” to complete Block
- Syntax error, insert “}” to complete ClassBody
- Syntax error, insert “Finally” to complete TryStatem in Myeclipse in Java-
- Error message: Syntax error, insert “Finally” to complete TryStatement
- Insert keyframe giving keying set failed to insert any key frames
- Insert keyframe giving keying set failed to insert any key frames (solved)
- Use Python to insert the specified content in the specified line of the specified file
- How to make the import complete smoothly!
- excel VBA: Could not complete due to error 800a0011
- Altium designer 18: activeroute failed to complete any routing
- Centos7 solves the problem of unable to use tab to complete automatically
- [Python] error syntax error: summary of solutions to invalid syntax
- Pychar oserror: [winerror 1455] the page file is too small to complete the operation.
- The most complete collection of solutions to Tortoise SVN Clean up failure
- Visual studio 2012, a complete collection of solutions to flash back windows after running
- Mybatis batch insert data
- Error: importerror: DLL load failed: the page file is too small to complete the operation.
- The pychar / pytorch page file is too small to complete the operation
- VMware (3): MacOS download software prompts “failed to complete the operation. ( com.apple.commerce . client error 500.) “
- Latex insert hyperlink