⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keyboardinput.java

📁 这是《Java2程序设计实用教程(第2版)》教材中附带的例题源代码。
💻 JAVA
字号:
//【例9.1】  标准输入输出。

import java.io.*;
public class KeyboardInput
{
    public static void main(String args[]) throws IOException  //抛出异常交由Java虚拟机处理
    {  
        System.out.print("Input: ");
        byte buffer[] = new byte[512];           //以字节数组作为缓冲区
        int count = System.in.read(buffer);      //从标准输入流中读取若干字节到指定缓冲区,返回实际读取的字节数
        
        System.out.print("Output: ");
        for (int i=0;i<count;i++)                //按字节方式输出buffer元素值
            System.out.print(" "+buffer[i]);
        System.out.println();
        
        for (int i=0;i<count;i++)                //按字符方式输出buffer元素值
            System.out.print((char) buffer[i]);
        System.out.println("count = "+ count);   //实际读取的字节数
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -