import java.util.Scanner ;
class MathTest
{
public static void main
( String [ ] args
) {
// Create a scanner object for user input
Scanner scanner
= new Scanner
( System .
in ) ;
// Prompt the user for an integer
System .
out .
print ( "Enter an integer: " ) ; int userInt = scanner.nextInt ( ) ;
// Prompt the user for a double
System .
out .
print ( "Enter a double: " ) ; double userDouble = scanner.nextDouble ( ) ;
// a. Calculate and display the square root of the integer
double squareRoot
= Math .
sqrt ( userInt
) ; System .
out .
println ( "The square root of " + userInt
+ " is " + squareRoot
) ;
// b. Generate and display a random number between 0 and the integer
int randomValue
= ( int ) ( Math .
random ( ) * userInt
) ; System .
out .
println ( "A random number between 0 and " + userInt
+ " is " + randomValue
) ;
// c. Display the floor, ceiling, and rounded values of the double
double floorValue
= Math .
floor ( userDouble
) ; double ceilingValue
= Math .
ceil ( userDouble
) ; long roundedValue
= Math .
round ( userDouble
) ;
System .
out .
println ( "The floor of " + userDouble
+ " is " + floorValue
) ; System .
out .
println ( "The ceiling of " + userDouble
+ " is " + ceilingValue
) ; System .
out .
println ( "The rounded value of " + userDouble
+ " is " + roundedValue
) ;
// d. Display the larger and smaller values between the integer and the double
double largerValue
= Math .
max ( userInt, userDouble
) ; double smallerValue
= Math .
min ( userInt, userDouble
) ;
System .
out .
println ( "The larger value between " + userInt
+ " and " + userDouble
+ " is " + largerValue
) ; System .
out .
println ( "The smaller value between " + userInt
+ " and " + userDouble
+ " is " + smallerValue
) ;
// Close the scanner
scanner.close ( ) ;
}
}
aW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwoKY2xhc3MgTWF0aFRlc3QgCnsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIAogICAgewogICAgICAgIC8vIENyZWF0ZSBhIHNjYW5uZXIgb2JqZWN0IGZvciB1c2VyIGlucHV0CiAgICAgICAgU2Nhbm5lciBzY2FubmVyID0gbmV3IFNjYW5uZXIoU3lzdGVtLmluKTsKCiAgICAgICAgLy8gUHJvbXB0IHRoZSB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