package a1;
public class Test {
private static int a = 1;
public static void main(String[] args) {
int a = 2;
System.out.println(a);
}
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));
}
[![img](/i/l/?n=23&i=blog/3168003/202309/3168003-20230912151953672-188320672.png)](/i/l/?n=23&i=blog/3168003/202309/3168003-20230912151953672-188320672.png)
使用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("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("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));
}
'''
[![img](/i/l/?n=23&i=blog/3168003/202309/3168003-20230912152316607-639781329.png)](/i/l/?n=23&i=blog/3168003/202309/3168003-20230912152316607-639781329.png)
'''
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};
}
'''
[![img](/i/l/?n=23&i=blog/3168003/202309/3168003-20230912155220887-347430913.png)](/i/l/?n=23&i=blog/3168003/202309/3168003-20230912155220887-347430913.png)
标签:0.01,System,0.05,3168003,println,课后练习,out
From: https://www.cnblogs.com/drip3775/p/17704078.html