课后作业2
'''
package a1;
public class Test {
private static int a = 1;
public static void main(String[] args) {
int a = 2;
System.out.println(a);
}
}
'''
Java变量遵循同名变量屏蔽原则
'''
public static void main(String args[]) {
System.out.println("0.05 + 0.01 = " + (0.05 + 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));
}
'''
使用double类型的数值进行计算,其结果是不精确的。
'''
public static void main(String[] args)
{
BigDecimal f1 = new BigDecimal("0.05");
BigDecimal f2 = BigDecimal.valueOf(0.01);
BigDecimal f3 = new BigDecimal(0.05);
System.out.println("����ʹ��String��ΪBigDecimal�����������ļ�������");
System.out.println("0.05 + 0.01 = " + f1.add(f2));
System.out.println("0.05 - 0.01 = " + f1.subtract(f2));
System.out.println("0.05 * 0.01 = " + f1.multiply(f2));
System.out.println("0.05 / 0.01 = " + f1.divide(f2));
System.out.println("����ʹ��double��ΪBigDecimal�����������ļ�������");
System.out.println("0.05 + 0.01 = " + f3.add(f2));
System.out.println("0.05 - 0.01 = " + f3.subtract(f2));
System.out.println("0.05 * 0.01 = " + f3.multiply(f2));
System.out.println("0.05 / 0.01 = " + f3.divide(f2));
}
'''
'''
public static void main(String[] args) {
int X= 100;
int Y = 200;
System.out.println("X+Y="+X+Y);
System.out.println(X+Y+"=X+Y");
}
'''
'''
package a1;
import javax.swing.*;
import java.math.BigDecimal;
import java.util.Random;
public class Test {
public static void main(String[] args) {
String a = "1";
Size s=Size.SMALL;
Size t=Size.LARGE;
System.out.println(st); //false
System.out.println(s.equals(Size.SMALL)); //true
System.out.println(s.getClass());
System.out.println(a.getClass());
System.out.println(s.getClass().isPrimitive());
Size u=Size.valueOf("SMALL");
System.out.println(su); //true
for(Size value:Size.values()){
System.out.println(value);
}
}
enum Size{SMALL,MEDIUM,LARGE};
}
'''