2015-09-07 11:44:36 -06:00
|
|
|
// strings/BetterRead.java
|
2016-12-30 17:23:13 -08:00
|
|
|
// (c)2017 MindView LLC: see Copyright.txt
|
2015-11-15 15:51:35 -08:00
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
2016-09-23 13:23:35 -06:00
|
|
|
// Visit http://OnJava8.com for more book information.
|
2015-06-15 17:47:35 -07:00
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
public class BetterRead {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
Scanner stdin = new Scanner(SimpleRead.input);
|
|
|
|
System.out.println("What is your name?");
|
|
|
|
String name = stdin.nextLine();
|
|
|
|
System.out.println(name);
|
|
|
|
System.out.println(
|
|
|
|
"How old are you? What is your favorite double?");
|
|
|
|
System.out.println("(input: <age> <double>)");
|
|
|
|
int age = stdin.nextInt();
|
|
|
|
double favorite = stdin.nextDouble();
|
|
|
|
System.out.println(age);
|
|
|
|
System.out.println(favorite);
|
2016-11-21 12:37:57 -08:00
|
|
|
System.out.format("Hi %s.%n", name);
|
|
|
|
System.out.format("In 5 years you will be %d.%n",
|
2015-06-15 17:47:35 -07:00
|
|
|
age + 5);
|
|
|
|
System.out.format("My favorite double is %f.",
|
|
|
|
favorite / 2);
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
}
|
|
|
|
/* Output:
|
2015-06-15 17:47:35 -07:00
|
|
|
What is your name?
|
|
|
|
Sir Robin of Camelot
|
|
|
|
How old are you? What is your favorite double?
|
|
|
|
(input: <age> <double>)
|
|
|
|
22
|
|
|
|
1.61803
|
|
|
|
Hi Sir Robin of Camelot.
|
|
|
|
In 5 years you will be 27.
|
|
|
|
My favorite double is 0.809015.
|
2015-09-07 11:44:36 -06:00
|
|
|
*/
|