【问题标题】:how to transform a char to a unicode java [closed]如何将char转换为unicode java [关闭]
【发布时间】:2018-10-08 15:14:12
【问题描述】:
import java.util.*;

public class Ex13 {

    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        char firstL,secondL;

        System.out.println("insert first l");
        firstL=in.next().charAt(0);
        System.out.println("insert second l");
        secondL=in.next().charAt(0);
        if (){
             System.out.println("kk"); 

        }
    }
}

我需要 firstLsecondLif 部分中相等,但我不能因为 firstLsecondL 是字符类型,我需要将其转换为 Unicode 所以我可以完成项目

【问题讨论】:

    标签: java unicode char


    【解决方案1】:

    你为什么不检查值?

        char firstL,secondL;
        System.out.println("insert first l");
        firstL=in.next().charAt(0);
        System.out.println("insert second l");
        secondL=in.next().charAt(0);
        if (firstL == secondL){
             System.out.println("kk"); 
        }
    

    【讨论】:

    • 请注意,当firstLsecondLchar 时,使用charAt(0) 仅适用于Unicode BMP 中的字符,它可以按原样适合单个char .如果需要处理 BMP 之外的补充字符,使用多个chars 编码,则需要将firstLsecondL 更改为int 并改用codePointAt(0)
    猜你喜欢
    • 2021-12-12
    • 2012-06-17
    • 1970-01-01
    • 2021-12-26
    • 2013-04-15
    • 1970-01-01
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多