java情话代码,程序员浪漫的二进制表白代码

bc7fdfc03a181785f939cc7c3cabcadc.gif

那天情人节,我给她发了一串数字(01001001 00100000 01101100 01101111 01110110 01100101 00100000 01111001 01101111 01110101),她说我不懂浪漫,我低头苦笑,其实她不知道,这是二进制形式的"I love you",难道程序员真的注定孤独一生?

程序写得比较粗陋,作为不登大雅之堂的娱乐工具,足够了。支持中文public class MonkeyRomatic {

public static void main(String args[]){

String wordsString = "I love you";

char[] wordsArray = wordsString.toCharArray();//将要表白的语句转为字符数组

int tempWord;//用于临时存放每个字符的ASCII码

int tempWordLength = 0;

String tempWords = "";//用于临时存放每个字符的二进制表示形式

String codeWords = "";//编码之后的表白语句

for(int i = 0;i 

tempWord = wordsArray[i];//获取当前字符的ASCII码

tempWords = Integer.toBinaryString(tempWord);

tempWordLength = tempWords.length();

if(tempWordLength 

//为美观起见,每个字符的二进制表示形式均限制为8位

for(int j = 0;j

tempWords = "0" + tempWords;

}

}

codeWords = codeWords + tempWords+ " ";

tempWords = "";//将当前二进制字符归空

}

System.out.println(codeWords);

}

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值