课后作业
public class EnumTest {
public static void main(String[] args) {
Size s=Size.SMALL;
Size t=Size.LARGE;
//s和t引用同一个对象?
System.out.println(s==t); //
//是原始数据类型吗?
System.out.println(s.getClass().isPrimitive());
//从字符串中转换
Size u=Size.valueOf("SMALL");
System.out.println(s==u); //true
//列出它的所有值
for(Size value:Size.values()){
System.out.println(value);
}
}
}
enum Size{SMALL,MEDIUM,LARGE};
运行结果:false
false
true
SMALL
MEDIUM
LARGE
public class Bit {
public static void main(String[] args) {
int num1 = 8; // 正数
int num2 = -8; // 负数
// 按位取反
int complement1 = ~num1;
int complement2 = ~num2;
// 按位与
int andResult = num1 & num2;
// 按位或
int orResult = num1 | num2;
// 按位异或
int xorResult = num1 ^ num2;
// 输出结果
System.out.println("按位取反:");
System.out.println(" ~" + num1 + " = " + complement1);
System.out.println(" ~" + num2 + " = " + complement2);
System.out.println();
System.out.println("按位与:");
System.out.println(num1 + " & " + num2 + " = " + andResult);
System.out.println();
System.out.println("按位或:");
System.out.println(num1 + " | " + num2 + " = " + orResult);
System.out.println();
System.out.println("按位异或:");
System.out.println(num1 + " ^ " + num2 + " = " + xorResult);
}
}
public class Test {
private static int value=1;
public static void main(String[] args) {
int value=2;
System.out.println(value);
}
}
最后输出2
int X=100;
int Y=200;
System.*out*.println("X+Y="+X+Y);
System.*out*.println(X+Y+"=X+Y");
代码的结果:X+Y=100200
public static class Main{
public static void main(String[] args) {
System.out.println("0.51+0.1="+(0.51+0.01));
System.out.println("1.0-0.42="+(1.0-0.42));
System.out.println("4.015*100="+(4.015*100));
System.out.println("123.3/100="+(123.3/100));
}
}最后得到的结果是
0.51+0.1=0.52
1.0-0.42=0.5800000000000001
4.015*100=401.49999999999994
123.3/100=1.2329999999999999