// strings/SimpleRead.java// (c)2017 MindView LLC: see Copyright.txt// We make no guarantees that this code is fit for any purpose.// Visit http://OnJava8.com for more book information.import java.io.*;public class SimpleRead {public static BufferedReader input =new BufferedReader(new StringReader("Sir Robin of Camelot\n22 1.61803"));public static void main(String[] args) {try {System.out.println("What is your name?");String name = input.readLine();System.out.println(name);System.out.println("How old are you? " +"What is your favorite double?");System.out.println("(input: <age> <double>)");String numbers = input.readLine();System.out.println(numbers);String[] numArray = numbers.split(" ");int age = Integer.parseInt(numArray[0]);double favorite = Double.parseDouble(numArray[1]);System.out.format("Hi %s.%n", name);System.out.format("In 5 years you will be %d.%n",age + 5);System.out.format("My favorite double is %f.",favorite / 2);} catch(IOException e) {System.err.println("I/O exception");}}}/* Output:What is your name?Sir Robin of CamelotHow old are you? What is your favorite double?(input: <age> <double>)22 1.61803Hi Sir Robin of Camelot.In 5 years you will be 27.My favorite double is 0.809015.*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。