如何将char转换为字符串..?

Manoj Kashyam:
class Math {
    void Book1(char a, char b) {
        int c = a + b;
        System.out.println("Output is" + c);
    }

    public static void main(String[] args) {
        Math m = new Math();
        m.Book1('A', 'B');
    }
}
Arvind Kumar Avinash:

您可以按照以下步骤进行操作:

public class Math {
    void Book1(char a, char b) {
        StringBuilder sb=new StringBuilder();
        sb.append(a);
        sb.append(b);
        System.out.println("Output is: " + sb.toString());
    }

    public static void main(String[] args) {
        Math m = new Math();
        m.Book1('A', 'B');
    }
}

另外,您可以String按以下方式使用类:

public class Math {
    void Book1(char a, char b) {
        String str=String.valueOf(a)+String.valueOf(b);        
        System.out.println("Output is: " + str);
    }

    public static void main(String[] args) {
        Math m = new Math();
        m.Book1('A', 'B');
    }
}

输出:

Output is: AB

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章