-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathKeyboardScanner.java
More file actions
47 lines (37 loc) · 1.17 KB
/
KeyboardScanner.java
File metadata and controls
47 lines (37 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Write a program called KeyboardScanner to prompt user for an int,
* a double, and a String. The output shall look like (the inputs are shown in bold):
*
* Enter an integer: 12
* Enter a floating point number: 33.44
* Enter your name: Peter
* Hi! Peter, the sum of 12 and 33.44 is 45.44
*/
package javaexercises.keyboard;
import java.util.Scanner;
/**
*
* @author User
*/
public class KeyboardScanner {
public static void main(String[] args) {
KeyboardScanner aKeyboardScanner = new KeyboardScanner();
aKeyboardScanner.runScanner();
}
private void runScanner() {
int num1;
double num2;
double sum;
String name;
Scanner in = new Scanner(System.in);
System.out.print("Enter an integer: ");
num1 = in.nextInt();
System.out.print("Enter a floating point number: ");
num2 = in.nextDouble();
System.out.print("Enter your name: ");
name = in.next();
sum = num1 + num2;
System.out.printf("Hi! %1$s, the sum of %2$d and %3$.5f is %4$.5f \n"
, name, num1, num2, sum);
}
}