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

📄 formattedinput.java

📁 Java Classic Examples是我买的两本书:《JAVA经典实例》和《java入门经典源代码》里边附送光盘里带的源码
💻 JAVA
字号:
import java.io.*;

public class FormattedInput
{
  // Method to read an int value
  public int intRead()
  {
    try
    {
      for(int i = 0; i < 5; i++)
      {
        if(tokenizer.nextToken() == tokenizer.TT_NUMBER && 
                                    tokenizer.nval==(double)((long)tokenizer.nval))
          return (int)tokenizer.nval;           // Value is integral, so return as int
        else
        {
          System.out.println("Incorrect input: " + tokenizer.sval +
                             " Re-enter an integer");
          continue;                             // Retry the read operation
        }
      }  

      System.out.println("Five failures reading an int value" +
                                        " - program terminated");
      System.exit(1);                    // End the program
      return 0;
    }
    catch(IOException e)                 // Error reading in nextToken()
    {
      System.out.println(e);             // Output the error
      System.exit(1);                    // End the program
      return 0;
    }
  }

  // plus methods to read various other data types...

  // Object to tokenize input from the standard input stream
  private StreamTokenizer tokenizer = new StreamTokenizer(
                                      new InputStreamReader(System.in));
}

⌨️ 快捷键说明

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