RSS发布话题

java myinput类

acmer

acmer发表于52天 10小时 23分钟前
来源:www.608088.com  标签:java

Google
// MyInput.java: Contain the methods for reading int, double, and
// string values from the keyboard
//package chapter2;

import java.io.*;

public class MyInput {
  /** Read a string from the keyboard */
  public static String readString() {
    BufferedReader br =
      new BufferedReader(new InputStreamReader(System.in), 1);
   
    // Declare and initialize the string
    String string = " ";
   
    // Get the string from the keyboard
    try {
      string = br.readLine();
    }
    catch (IOException ex) {
      System.out.println(ex);
    }
       
    // Return the string obtained from the keyboard
    return string;
  }
 
  /** Read an int value from the keyboard */
  public static int readInt() {
    return Integer.parseInt(readString());
  }
 
  /** Read a double value from the keyboard */
  public static double readDouble() {
    return Double.parseDouble(readString());
  }
 
  /** Read a byte value from the keyboard */
  public static byte readByte() {
    return Byte.parseByte(readString());
  }
 
  /** Read a short value from the keyboard */
  public static short readShort() {
    return Short.parseShort(readString());
  }
 
  /** Read a long value from the keyboard */
  public static long readLong() {
    return Long.parseLong(readString());
  }
 
  /** Read a float value from the keyboard */
  public static float readFloat() {
    return Float.parseFloat(readString());
  }
 
  /** Read a character from the keyboard */
  public static char readChar() {
    return readString().charAt(0);
  }
}



Disclaimer: some contents on this website are collected through internet etc. Please notify if violated the original author's copyright and we will delete it immediately.
免责声明:本站部分文章来源于网络等其它媒体,如果侵犯了原作者的版权,请联系我们,本站将立即删除。

关注用户

    最近还没有登录用户关注过这篇文章…
暂无评论
共有 0 位网友发表了评论

评论


google 提供的广告

本周热门评论

google 提供的广告