• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
 






F会飞的猪

 
 

Powered by 博客园
博客园 | 首页 | 新随笔 | 联系 | 订阅 订阅 | 管理

2019年4月1日

两个数用二进制表示,有多少位不同
摘要: 两个数异或,相同为0;不同为1。再调用方法判断有几个1。 代码段: public class Hanshujiaohuan { public static int sun(int a) { int count=0; while(a>0) { if((a&1)==1) count++; a>>=1; 阅读全文
posted @ 2019-04-01 22:06 F会飞的猪 阅读(349) 评论(0) 推荐(0)
 
一个整数的二进制数中1的个数
摘要: 用while循环,将数与1用&(运算符)相与,如果结果为1,则这个位置数为1;否则为0。 再将数向右移一位,再重复上一步。 代码段: public class Hanshu { public static int sun(int a) { int count=0; while(a>0) { if(( 阅读全文
posted @ 2019-04-01 21:34 F会飞的猪 阅读(134) 评论(0) 推荐(0)
 
将十进制数转化为二进制数
摘要: 基本方法: public static void main(String []args) { System.out.println("输入一个数"); Scanner scan=new Scanner(System.in); int a=scan.nextInt(); int sum; String 阅读全文
posted @ 2019-04-01 21:20 F会飞的猪 阅读(200) 评论(0) 推荐(0)
 
(调用方法)判断一个整数是否为素数两种方法,年份是否是闰年,交换两个数值
摘要: 调用方法在整个java学习中占很大部分,还是要好好学哈。 代码段: public class Hanshujiaohuan { void sun(int a,int b) { int temp=a; a=b; b=temp; System.out.println("a="+a+"\t"+"b="+b 阅读全文
posted @ 2019-04-01 20:38 F会飞的猪 阅读(211) 评论(0) 推荐(0)