Dukefish
package com.isoftstone;   
  
import java.io.UnsupportedEncodingException;   
  
public class Convert {   
    public static void main(String[] args) throws UnsupportedEncodingException {   
        asciiToString();// ASCII转换为字符串   
  
        stringToAscii();// 字符串转换为ASCII码   
  
    }   
  
    public static void asciiToString() {// ASCII转换为字符串   
  
        String s = "22307 35806 24555 20048";// ASCII码   
  
        String[] chars = s.split(" ");   
        System.out.println("ASCII 汉字 \n----------------------");   
        for (int i = 0; i < chars.length; i++) {   
            System.out.println(chars[i] + " "  
                    + (char) Integer.parseInt(chars[i]));   
        }   
    }   
  
    public static void stringToAscii() {// 字符串转换为ASCII码   
  
        String s = "你好中国!";// 字符串   
  
        char[] chars = s.toCharArray(); // 把字符中转换为字符数组   
  
        System.out.println("\n\n汉字 ASCII\n----------------------");   
        for (int i = 0; i < chars.length; i++) {// 输出结果   
  
            System.out.println(" " + chars[i] + " " + (int) chars[i]);   
        }   
    }   
}  

 

分类:

技术点:

相关文章:

  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2021-06-26
  • 2022-01-23
  • 2021-06-02
  • 2022-02-18
  • 2021-12-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案