Java学习

加减乘除:
public class MathCalc1 {
public static void main(String[] args) {
System.out.println(5 + 6);
System.out.println(5 - 6);
System.out.println(5 * 6);
System.out.println(5 / 6.0);
 
System.out.println(1 + 2 * 3 / 4.0 + (5 + 6) / 7.0);
}
}
变量:
public class Variable1 {
public static void main(String[] args) {
int a = 1;
int b = 2;
int c = 3;
 
int x = 0;
 
int y = a * x + b * (x * x) + c * (x * x * x);
 
System.out.println(y);
}
}
基本数据类型:
import java.math.BigDecimal;
 
public class PrimaryTypes {
public static void main(String[] args) {
byte byteVar = 100;
System.out.println(byteVar);
 
short shortVar = 30000;
System.out.println(shortVar);
 
int intVar = 1000000000;
System.out.println(intVar);
 
long longVar = 80000000000L;
System.out.println(longVar);
 
float floatVar = 100.0000000666F;
System.out.println(floatVar);
 
double doubleVar = 100.0000000666;
System.out.println(doubleVar);
 
boolean booleanVar = true;
System.out.println(booleanVar);
 
char charVar = 'a';
System.out.println(charVar);
 
}
}
 
运算符:

public class PriorityExample {
public static void main(String[] args) {
int a = 1 + 3;
int b = 2;
boolean both = a > 0 && b > 0;
System.out.println(both);
 
boolean result = a < b + 5;
System.out.println(result);
 
}
}
public class ParentOprt {
public static void main(String[] args) {
int a = 10;
int b = 88;
boolean c = ((a + b) * a - 9 * (a + b)) == (a + b);
 
System.out.println(c);
}
}
public class IncreaseDecrease3 {
public static void main(String[] args) {
int a = 1;
System.out.println("a++=" + a++);
 
System.out.println("a++=" + a);
a = a + 1;
 
a = 1;
 
System.out.println("++a=" + (++a));
 
a = a + 1;
System.out.println("++a=" + a);
}
}
 
posted @ 2021-01-14 21:54  peogre  阅读(37)  评论(0编辑  收藏  举报