File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import java .util .Scanner ;
22
33public class Exercise_3_2 {
4-
4+
55 public static void main (String [] args ) {
6+ //initialize the Scanner
7+ Scanner in = new Scanner (System .in );
8+ final double nineDivFive = 1.8 ;
9+
10+ //Prompts Person inputs a temperature in Celsius
11+ System .out .print ("Enter a temperature in Celsius: " );
12+
13+ //Take the input
14+ double tempInput = in .nextDouble ();
615
16+ //Check for the proper input from tempInput
17+ System .out .printf ("User input = %f\n " , tempInput );
18+
19+ //Calculation. I used an assigned value for the 9/5 part of the conversion. since it doesn't change
20+ final double fahCalc = tempInput * nineDivFive + 32.0 ;
21+
22+ //Check for the proper input from tempInput
23+ System .out .printf ("Final calculation are as follows %.1f C = %.1f F" , tempInput , fahCalc );
724 }
825
926}
Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+ import java .util .Random ;
3+
4+
5+ public class Exercise_3_3 {
6+
7+ public static void main (String [] args ) {
8+ // importing the random module
9+ Random random = new Random ();
10+ int number = random .nextInt (100 ) + 1 ;
11+ // System.out.println(number);
12+
13+ // importing the ability to get user input
14+ Scanner in = new Scanner (System .in );
15+
16+ // Initial prompt to user and input to their number
17+ System .out .println ("I'm thinking of a number between 1 and 100.\n Can you guess what it is?" );
18+ System .out .print ("Type a number: " );
19+ int userInput = in .nextInt ();
20+ System .out .printf ("Your guess is: %d\n " , userInput );
21+ System .out .printf ("The number I was thinking of is: %d\n " , number );
22+
23+ // Calculating how much they were off by
24+ int calc = (number - userInput );
25+
26+ // Telling the user how much they were off by
27+ System .out .printf ("You were off by: %d " , calc );
28+ }
29+
30+ }
You can’t perform that action at this time.
0 commit comments