-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScannerDemo.java
61 lines (52 loc) · 1.62 KB
/
ScannerDemo.java
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.util.Scanner;
public class ScannerDemo
{
//variable declarations;
private static String name;
private static double favNum = 5;
private static final Scanner kb = new Scanner(System.in);
/** This is the main method for running the program
* @param String [] args - the array that is passed in to run the program
* @return nothing
*/
public static void main (String [] args)
{
//obtaining input from user
userInput();
//outputting stuff to the screen
outputStuff();
}
/*
* This method allows the user to input stuff
*/
private static void userInput()
{
// asking the user for their favorite number
System.out.print("What is your favorite number : ");
// getting a double using the scanner
favNum = kb.nextDouble();
//clearing out the Scanner stream
kb.nextLine();
// asking the user for their name
System.out.print("What is your name? : ");
name = kb.nextLine();
}
/**
* This method outputs stuff to the screen
*/
public static void outputStuff()
{
System.out.print("what value do you want to mutiply by : ");
int multiplier = kb.nextInt();
processInput(multiplier);
System.out.println(name + ", your favorite number when multiplied by " + multiplier + " is " + favNum);
}
/*
* this method calls the inputs to be processed
* @param int multi - the multiplier that is coming in from the user
*/
private static void processInput(int multi)
{
favNum *= multi;
}
}