Java 习题 (19)

题目:
编写一个方法,它以二进制形式显示char类型的值。使用多个不同的字符来展示它。

解答:

import java.util.*;

public class chapterThree {
    public static void main(String[] args){
    	System.out.println("A: " + Integer.toBinaryString('A')); // A: 65
        System.out.println("!: " + Integer.toBinaryString('!')); // !: 33
        System.out.println("x: " + Integer.toBinaryString('x')); // x: 120
        System.out.println("7: " + Integer.toBinaryString('7')); // 7: 55
    }
}

结果如下:
在这里插入图片描述
如果觉得不错的话,就用点赞或者关注来代替五星好评吧!谢谢了!

猜你喜欢

转载自blog.csdn.net/BSCHN123/article/details/107297845