MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / main

Method main

strings/SimpleRead.java:11–32  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

9 new BufferedReader(new StringReader(
10 "Sir Robin of Camelot\n22 1.61803"));
11 public static void main(String[] args) {
12 try {
13 System.out.println("What is your name?");
14 String name = input.readLine();
15 System.out.println(name);
16 System.out.println("How old are you? " +
17 "What is your favorite double?");
18 System.out.println("(input: <age> <double>)");
19 String numbers = input.readLine();
20 System.out.println(numbers);
21 String[] numArray = numbers.split(" ");
22 int age = Integer.parseInt(numArray[0]);
23 double favorite = Double.parseDouble(numArray[1]);
24 System.out.format("Hi %s.%n", name);
25 System.out.format("In 5 years you will be %d.%n",
26 age + 5);
27 System.out.format("My favorite double is %f.",
28 favorite / 2);
29 } catch(IOException e) {
30 System.err.println("I/O exception");
31 }
32 }
33}
34/* Output:
35What is your name?

Callers

nothing calls this directly

Calls 2

splitMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected