1. Getting Started
Activity 1: Obtaining the Minimum of Two Numbers
Solution
- Declare
3
double variables:a
,b
, andm
. Initialize them with the values3
,4
and0
respectivelydouble a = 3; double b = 4; double m = 0; // variable for the minimum
- Create a
String
variabler
, it should contain the output message to be printed.// string to be printed String r = "The minimum of numbers: " + a + " and " + b + " is ";
- Use the
min()
method to obtain the minimum of the two numbers and store the value inm
.// mathematical operation m = Math.min(a,b);
- Print the results.
System.out.println(r + m); // print out the results
Note
The complete code for this activity can be found here: https://packt.live/2MFtRNM