048_输出一下short的所有值
生活随笔
收集整理的這篇文章主要介紹了
048_输出一下short的所有值
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1. 輸出Short的最小值-32768到最大值32767
public static void printShort() {try {int count = 0;FileOutputStream fos = new FileOutputStream("printShort.txt");for(short i = Short.MIN_VALUE; count < Math.abs(Short.MIN_VALUE) + Short.MAX_VALUE + 1; i++) {count++;fos.write(String.valueOf(i + "\r\n").getBytes());}fos.close();} catch (Exception e) {e.printStackTrace();} }2. 輸出Short的最小值-32768到最大值32767, 通過對Short類型進行累加輸出了2次
public static void print2Short() {try {int count = 0;FileOutputStream fos = new FileOutputStream("print2Short.txt");for(short i = Short.MIN_VALUE; count < (Math.abs(Short.MIN_VALUE) + Short.MAX_VALUE + 1) * 2; i++) {count++;fos.write(String.valueOf(i + "\r\n").getBytes());if(count == Math.abs(Short.MIN_VALUE) + Short.MAX_VALUE + 1) {fos.write("\r\n----------\r\n\r\n".getBytes());}}fos.close();} catch (Exception e) {e.printStackTrace();} }?
總結
以上是生活随笔為你收集整理的048_输出一下short的所有值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 047_输出一下byte的所有值
- 下一篇: 050_整形和字节数组转换