Below is the code:
class PlayWithBinary {
static int age;
public static void main (String args[]){
int i = 0b10101010;
System.out.println("my age is: " + age + " my salary is: "+ i);
}
}
In terminal I executed : javac PlayWithBinary.java
For some reasons it is showing this error message:
PlayWithBinary.java:5: ';' expected
int i = 0b10101010;
^
1 error
Any ideas?
Update: for those who are getting similar errors, here is the link to download JDK 8 - Java SE Development Kit 8 Downloads
确保您的项目配置了Java 7或更高级别的Java兼容级别,或者您可以修改代码以使用Integer.parseInt(String, int)
int i = Integer.parseInt("10101010", 2);
It sounds like you're using an older version of Java that doesn't support this. This feature was added in Java 7 - see the documentation and this related question . You should upgrade your Java version to fix this.
Alternatively, you can use Integer.parseInt(String, int)
on your code: int i = Integer.parseInt("10101010", 2);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.