本文介紹了添加 char 和 int的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
據我了解,char 是單個字符,即字母、數字、標點符號、制表符、空格或類似的東西.因此,當我這樣做時:
To my understanding a char is a single character, that is a letter, a digit, a punctuation mark, a tab, a space or something similar. And therefore when I do:
char c = '1';
System.out.println(c);
輸出 1 正是我所期望的.那么為什么當我這樣做時:
The output 1 was exactly what I expected. So why is it that when I do this:
int a = 1;
char c = '1';
int ans = a + c;
System.out.println(ans);
我最終得到輸出 50?
推薦答案
你得到它是因為它添加了 ASCII 值 字符.您必須先將其轉換為 int.
You're getting that because it's adding the ASCII value of the char. You must convert it to an int first.
這篇關于添加 char 和 int的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!