av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

Java中輸出字符的ASCII值實例

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

1. 我們可以通過將字符強轉為int型進行輸出那么在控制臺中我們將會得到字符的ascii值,這里我們使用nextLine()方法來接收字符串,可以接收空格/Tab鍵,使用next()方法則不會接收空格/Tab鍵,但是這里使用nextLine方法不能打印回車鍵的ascii值因為它遇到回車鍵就截止接收字符了

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值實例

補充知識:Java Integer -128~127

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

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

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

研究源碼發現

/** * 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會將常用的值(-128 to 127)cache起來。當i值在這個范圍時,會比用構造方法Integer(int)效率和空間上更好。

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

標簽: Java
相關文章:
主站蜘蛛池模板: 欧美日韩中文 | 天天摸夜夜操 | 亚洲免费网站 | 欧美综合在线视频 | 日本免费毛片 | 99re在线观看视频 | 一级片中文字幕 | 久久伊人网站 | 国产在线h | 国产乱人乱偷精品视频 | 在线成人免费视频 | 一区二区在线看 | 日本午夜精品 | 欧美综合激情 | 中文日韩欧美 | 日本天堂网| 国内精品一区二区 | 黄色成人小视频 | 在线日韩视频 | 中文字幕国产一区 | 国产成人精品免费 | 亚洲精品在线免费 | 一级毛片在线免费观看 | 激情综合网五月 | 久久在线 | 激情导航 | 天天燥日日燥 | 日韩成人片| 亚洲午夜精品一区二区三区 | 一级性视频 | 成人免费看片在线观看 | 国产精品一区一区三区 | 亚洲人成在线播放 | 午夜视频在线播放 | 黄色一级在线观看 | 黄网站免费看 | 日韩在线欧美 | 精品日韩在线观看 | 97国产在线观看 | 免费毛片在线播放免费 | 日韩999|