inputdemo.java

来自「Java学习源代码检索系统免费版」· Java 代码 · 共 35 行

JAVA
35
字号
//==============================================================
// InputDemo.java - Demonstrates string input
//
// Java学习源代码检索系统 Ver 1.0 20031015 免费正式版
// 版权所有: 中国IT认证实验室(www.ChinaITLab.com)
// 程序制作: ChinaITLab网校教研中心
// 主页地址: www.ChinaITLab.com    中国IT认证实验室
// 论坛地址: bbs.chinaitlab.com  
// 电子邮件: Java@ChinaITLab.com
//==============================================================

import java.io.IOException;

class InputDemo {
 public static void main(String args[]) {
  try {
   // Input a single character
   System.out.println("Type a character:");
   char ch = (char)System.in.read();
   System.out.println("You entered: " + ch);
   // Throw out new line
   while (ch != '\n')
    ch = (char)System.in.read();  
   // Input a string
   System.out.println("Type a string:");
   StringBuffer s = new StringBuffer();
   while ((ch = (char)System.in.read()) != '\n')
    s.append(ch);
   System.out.println("You entered: " + s);
  } catch (IOException e) {
   System.out.println("Input error detected");
  }
 }
}

⌨️ 快捷键说明

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