摘要:
1.左移"<<",無論是正數還是負數,低位都補0。 byte a = 11; byte b = -11; System.out.println("a = "+(a << 2)); System.out.println("b = "+(b << 2)); (byte為1個字節) 正數:11 原碼:00
閱讀全文
摘要:
1.產生100個不同的隨機數(0~100): 方法一: 1 // 利用空間換時間效率 ,數組直接初始化全部為0 2 int[] a = new int[n]; 3 int[] b = new int[n+1]; 4 for(int i = 0;i < n;) 5 { 6 int x = (int)
閱讀全文
摘要:
方法一: java.lang包中的Math類中的靜態方法。public static double random(),返回一個double值為正號。 1 //打印一個隨機數[0,10] 2 int a = (int) (Math.random()*11); 3 System.out.println(
閱讀全文
摘要:
回文數:設n是一任意自然數。若將n的各位數字反向排列所得自然數n1與n相等,則稱n為一回文數。 1 public class PracticeDemo { 2 /** 3 *@Function: isPalindrome 4 *@Description:判斷1個數是否為回文數(一個數正著讀和反著讀一
閱讀全文
摘要:
/*思路:由目標式子可見分為兩個部分。一個為每一項求階乘數,另外一個為求和。所以寫兩個方法就可以解決。*/ public class PracticeDemo { //遞歸方法求每一位的階乘,返回為該數的階乘。從1開始 public static long Recursion(int a) { lo
閱讀全文
摘要:
/*思想:由于三(四)位二進制等于一位八(十六)進制 。找到毗鄰數組長度最小的3(4)的倍數,作為新數組長度。多余位數(高位)用0補齊。*/ public class PracticeDemo { public static void BtoOHex(int n,String s) { int m
閱讀全文
摘要:
//二,八,十六,進制轉為十進制(字符串知識點方法) public class PracticeDemo { public static void BOHextoD(int n,String string) { int sum = 0; System.out.println("輸出"+n+"進制數如
閱讀全文
摘要:
public class PracticeDemo { //十進制轉二進制 public static void Binary(int x) { int c = x;//為第二種方法先把x值預存起來 //方法一: Stack stack = new Stack(); while(x > 0) { s
閱讀全文
摘要:
public class PracticeDemo { public static void main(String[] args) { int fenzi = 2; int fenmu = 1; int sum = 0; int temp = 0; int n = 0;//計數器 System.o
閱讀全文