Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I can\'t seem to figure out the correct syntax for this problem Write a Java pro

ID: 3624655 • Letter: I

Question

I can't seem to figure out the correct syntax for this problem

Write a Java program called Numbers that calls the following methods and displays the returned value:

Write a method called cube that accepts one integer parameter and returns the value raised to the third power.

Write a method called randomInRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive.

Write a method called larger that accepts two double parameters and returns true if the first parameter is greater and false otherwise.

Explanation / Answer

public class Numbers
{
public static void main(String[] args)
{
System.out.println("4 cubed is "+cube(4));
System.out.println("A random integer between 10 and 20 is "+randomRange(10, 20));
System.out.println("2.5 larger than 3.5? "+larger(2.5, 3.5));
}

public static int cube(int n)
{
return n*n*n;
}
public static int randomRange(int bot, int top)
{
return (int)Math.floor(Math.random()*(top-bot))+bot;
}
public static boolean larger(double d1, double d2)
{
return d1 > d2;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote