一.運算符
- 賦值運算符:= 將右側(cè)變量的值或者表達式的值賦值給左側(cè)變量。
- 算術(shù)運算符:+ - * / %
- 自增運算符 ++ 藕漱、 --
++在前:先讓變量的值+1,然后參與運算
++在后:先取出變量的值參與運算恨统,然后再讓變量的值+1怪蔑。
public class T1 {
public static void main(String[] args) {
int a = 1;
// System.out.println(a++); 輸出 1
System.out.println(++a); // 輸出 2
}
}
二. 在Java中保留小數(shù)位置
String result=String.format("%.1f",avg);
三. 分離數(shù)位
個位分離: 用當前數(shù) 取10 的余數(shù) 余數(shù)就是 當前是的 個位數(shù)
十分分離: 用當前數(shù) 除以 10 再取 10的余數(shù), 余數(shù)就是 十位數(shù)
百位分離: 用當前數(shù) 取100 的余數(shù) 余數(shù)就是 當前是的 十位數(shù)
千位......取1000的余數(shù)
萬位......取10000的余數(shù)
public class T1 {
public static void main(string[] args) {
int num = 123;
int ge = num % 10;
int shi = num / 10 % 10;
int bai = num / 100;
System.out.println("個位" + ge), System.out.println("十位" + shi);
System.out.println("百位" + bai):
}
}