Answer to Question #309170 in Java | JSP | JSF for Jones

Question #309170

Create a class named Exponent. Its main() method accepts an integer value from a user at the keyboard, and in turn passes the value to a method that squares the number (multiplies it by itself) and to a method that cubes the number (multiplies it by itself twice). The main() method displays the results. Create the two methods that respectively square and cube an integer that is passed to them, returning the calculated value. Save the application as Exponent.java


1
Expert's answer
2022-03-10T18:08:00-0500


import java.util.*;


class Exponent {


	public static void main(String[] args) {
		Scanner keyboard = new Scanner(System.in);
		System.out.print("Enter number: ");
		int number = keyboard.nextInt();
		System.out.println("Square: " + square(number));
		System.out.println("Cube: " + cube(number));


		keyboard.close();
	}


	private static int cube(int number) {
		return number * number * number;
	}


	private static int square(int number) {
		return number * number;
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS