午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術(shù)文章
文章詳情頁

Java中輸出字符的ASCII值實(shí)例

瀏覽:46日期:2022-08-27 10:38:45

1. 我們可以通過將字符強(qiáng)轉(zhuǎn)為int型進(jìn)行輸出那么在控制臺(tái)中我們將會(huì)得到字符的ascii值,這里我們使用nextLine()方法來接收字符串,可以接收空格/Tab鍵,使用next()方法則不會(huì)接收空格/Tab鍵,但是這里使用nextLine方法不能打印回車鍵的ascii值因?yàn)樗龅交剀囨I就截止接收字符了

2. 具體的測試代碼如下:

import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); for(int i = 0; i < s.length(); i++){ System.out.println((int)s.charAt(i)); } sc.close(); }}

輸入:

0123456789

輸出:

Java中輸出字符的ASCII值實(shí)例

補(bǔ)充知識(shí):Java Integer -128~127

今天刷到了一道題,為什么第一個(gè)為true,第二個(gè)為false。

System.out.println(Integer.valueOf('100')==Integer.valueOf('100'));//true

System.out.println(Integer.valueOf('200')==Integer.valueOf('200'));//false

研究源碼發(fā)現(xiàn)

/** * Returns a <tt>Integer</tt> instance representing the specified * <tt>int</tt> value. * If a new <tt>Integer</tt> instance is not required, this method * should generally be used in preference to the constructor * {@link #Integer(int)}, as this method is likely to yield * significantly better space and time performance by caching * frequently requested values. * * @param i an <code>int</code> value. * @return a <tt>Integer</tt> instance representing <tt>i</tt>. * @since 1.5 */ public static Integer valueOf(int i) { if(i >= -128 && i <= IntegerCache.high) return IntegerCache.cache[i + 128]; else return new Integer(i); }

private static class IntegerCache { static final int high; static final Integer cache[]; static { final int low = -128; // high value may be configured by property int h = 127; if (integerCacheHighPropValue != null) {// Use Long.decode here to avoid invoking methods that// require Integer’s autoboxing cache to be initializedint i = Long.decode(integerCacheHighPropValue).intValue();i = Math.max(i, 127);// Maximum array size is Integer.MAX_VALUEh = Math.min(i, Integer.MAX_VALUE - -low); } high = h; cache = new Integer[(high - low) + 1]; int j = low; for(int k = 0; k < cache.length; k++)cache[k] = new Integer(j++); } private IntegerCache() {} }

valueOf會(huì)將常用的值(-128 to 127)cache起來。當(dāng)i值在這個(gè)范圍時(shí),會(huì)比用構(gòu)造方法Integer(int)效率和空間上更好。

以上這篇Java中輸出字符的ASCII值實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 狠狠插狠狠插 | 草草在线视频 | 欧美亚洲综合在线 | 精品国产福利 | 天天看av| 在线观看一区 | 亚洲无打码 | 国产精品爽爽爽 | 国产精品免费一区 | 最近日韩免费视频 | 五月婷婷色 | 美女一二区 | 色综久久 | 日韩av在线播 | 涩涩一区 | 黄色你懂的 | 成人免费黄色大片 | 少妇在线视频 | 91精品国产吴梦梦 | 老鸭窝成人| 在线观看中文字幕码 | 午夜免费网站 | 中文字幕第 | 日韩久久久久久久 | 亚洲天堂手机在线 | 欧美激情一区二区视频 | 亚洲欧美日韩中文在线 | 成人在线视频一区 | 女人日批视频 | 欧美一区二区在线播放 | 超碰99在线观看 | 欧美日韩高清免费 | 糖心vlog免费在线观看 | 免费成人深夜夜行网站 | 欧美日韩一二三区 | 午夜视频黄 | 国产日产av| 人人干人人插 | 亚洲网站免费观看 | 女人洗澡一级特黄毛片 | 免费成人深夜蜜桃视频 |