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

📄 multiplelineinputs.java

📁 《A first book of java》by Gary J.Bronson 北大出版社
💻 JAVA
字号:
import java.io.*;    // needed to read the keyboard
import java.util.*;  // needed to access the StringTokenizer class
public class MultipleLineInputs
{
  public static void main(String[] args)
  throws java.io.IOException
  {
    String inputString;
    String s1, s2, s3;
    double num1, num3;
    double num2, result;
     // set up the basic input stream
      // needed for conversion capabilities  
    InputStreamReader isr = new InputStreamReader(System.in);
      // needed to use ReadLine()
    BufferedReader br = new BufferedReader(isr);
    
    System.out.print("Enter three numbers: ");
    inputString = br.readLine();
      // declare and create a StringTokenizer object from the input line
    StringTokenizer st = new StringTokenizer(inputString);
      // strip off individual items
    s1 = st.nextToken();
    s2 = st.nextToken();
    s3 = st.nextToken();
    System.out.println("The strings extracted are:  " + s1 + "  " + s2 
                                + "  " + s3);
    num1 = Double.parseDouble(s1);
    num2 = Double.parseDouble(s2);
    num3 = Double.parseDouble(s3); 
    result = (num1 + num2) / num3;
    System.out.println("The value of (" +num1 +" + " +num2 +")/" 
                                           +num3 +" is " +result);
  }
}

⌨️ 快捷键说明

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