万水千山走过

导航

2020年3月29日 #

位运算符“<<”,“>>”,“>>>”的区别。

摘要: 1.左移"<<",无论是正数还是负数,低位都补0。 byte a = 11; byte b = -11; System.out.println("a = "+(a << 2)); System.out.println("b = "+(b << 2)); (byte为1个字节) 正数:11 原码:00 阅读全文

posted @ 2020-03-29 10:05 万水千山走过 阅读(1479) 评论(0) 推荐(0) 编辑

2020年2月23日 #

产生不同的随机数并且采用冒泡排序。

摘要: 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) 阅读全文

posted @ 2020-02-23 09:52 万水千山走过 阅读(403) 评论(0) 推荐(0) 编辑

2020年2月18日 #

java中随机数的产生的两种方法。

摘要: 方法一: java.lang包中的Math类中的静态方法。public static double random(),返回一个double值为正号。 1 //打印一个随机数[0,10] 2 int a = (int) (Math.random()*11); 3 System.out.println( 阅读全文

posted @ 2020-02-18 17:56 万水千山走过 阅读(497) 评论(0) 推荐(0) 编辑

判断一个数是否为回文数或者打印特定范围的回文数。

摘要: 回文数:设n是一任意自然数。若将n的各位数字反向排列所得自然数n1与n相等,则称n为一回文数。 1 public class PracticeDemo { 2 /** 3 *@Function: isPalindrome 4 *@Description:判断1个数是否为回文数(一个数正着读和反着读一 阅读全文

posted @ 2020-02-18 12:26 万水千山走过 阅读(249) 评论(0) 推荐(0) 编辑

2020年2月16日 #

求前n项数的阶乘求和(包括0)

摘要: /*思路:由目标式子可见分为两个部分。一个为每一项求阶乘数,另外一个为求和。所以写两个方法就可以解决。*/ public class PracticeDemo { //递归方法求每一位的阶乘,返回为该数的阶乘。从1开始 public static long Recursion(int a) { lo 阅读全文

posted @ 2020-02-16 12:57 万水千山走过 阅读(520) 评论(0) 推荐(0) 编辑

2020年2月15日 #

二进制转为八进制和十六进制

摘要: /*思想:由于三(四)位二进制等于一位八(十六)进制 。找到毗邻数组长度最小的3(4)的倍数,作为新数组长度。多余位数(高位)用0补齐。*/ public class PracticeDemo { public static void BtoOHex(int n,String s) { int m 阅读全文

posted @ 2020-02-15 15:50 万水千山走过 阅读(354) 评论(0) 推荐(0) 编辑

2020年2月14日 #

二、八、十六进制转为十进制

摘要: //二,八,十六,进制转为十进制(字符串知识点方法) public class PracticeDemo { public static void BOHextoD(int n,String string) { int sum = 0; System.out.println("输出"+n+"进制数如 阅读全文

posted @ 2020-02-14 11:55 万水千山走过 阅读(450) 评论(0) 推荐(0) 编辑

2020年2月11日 #

十进制转为二、八、十六进制(两种方法:栈和比较法)。

摘要: public class PracticeDemo { //十进制转二进制 public static void Binary(int x) { int c = x;//为第二种方法先把x值预存起来 //方法一: Stack stack = new Stack(); while(x > 0) { s 阅读全文

posted @ 2020-02-11 18:37 万水千山走过 阅读(913) 评论(0) 推荐(1) 编辑

有规律分数求和!

摘要: 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 阅读全文

posted @ 2020-02-11 13:57 万水千山走过 阅读(257) 评论(0) 推荐(0) 编辑