Java 幾個特殊字元
阿新 • • 發佈:2019-01-27
import java.util.Arrays; /** * Created by lihaibin02 on 2016/9/26. */ public class Test_String { //統計二進位制有多少個1 public static int count_Number(int n) { int count = 0; while (n > 0) { if ((n & 1) == 1) { count++; } n >>= 1; } return count; } //Java中》與<< public static void num_Function(int n) { /* >>1表示次數縮小2倍(取整) <<1表示次數擴大2倍 * */ System.out.println(n >> 1); System.out.println(n << 1); } //10進位制轉化成2進位制後01的個數 public static void the_01_Number() { int i2 = 10; int count = 0;//統計十進位制轉換成二進位制後的0、1總個數 while (i2 > 0) { count++; i2 >>= 1; } System.out.println(count); } //Java character字元操作 public static void character_Function() { Character ch[] = {'a', 'b', 'c', 'a', 'b'}; Arrays.sort(ch); char a = 'a'; char b = 'b'; System.out.println(a + b);// character 型的字元遇到 int型的運算子號,就會轉成int型 195 System.out.println(a + 0);//97 System.out.println(Arrays.toString(ch)); } public static void main(String[] args) { character_Function(); } }