Answer to Question #326698 in Java | JSP | JSF for stephanie

Question #326698

Write a program that can perform addition with these overloaded methods:


int add(int x, int y) – returns the sum of two integer values

double add(int x, double y) – returns the sum of an integer value and a double value

double add(int x, int y, double z) – returns the sum of two integer values and a double value


Use the methods in the program. (How would you use them?)



1
Expert's answer
2022-04-10T06:27:31-0400


class App {
	/**
	 * returns the sum of two integer values
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	static int add(int x, int y) {
		return x + y;
	}


	/***
	 * returns the sum of an integer value and a double value
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	static double add(int x, double y) {
		return x + y;
	}


	/**
	 * returns the sum of two integer values and a double value
	 * 
	 * @param args
	 */
	static double add(int x, int y, double z) {
		return x + y + z;
	}


	public static void main(String[] args) {


		int x = 5;
		int y = 5;


		double z = 1.2;


		System.out.println("int add(int x, int y): " + add(x, y));
		System.out.println("double add(int x, double y): " + add(x, z));
		System.out.println("double add(int x, int y, double z): " + add(x, y, z));


	}
}

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