5. Define a method void print(int x, int y) in a class Samplel, which calculates and prints the difference of squares or arguments x and y.
Answers
Answer:
Question 26
Design a class to overload a function Joystring( ) as follows:
void Joystring(String s, char ch1, char ch2) with one string argument and two character arguments that replaces the character argument ch1 with the character argument ch2 in the given String s and prints the new string.
Example:
Input value of s = "TECHNALAGY
ch1 = 'A'
ch2 = 'O'
Output: "TECHNOLOGY"
void Joystring(String s) with one string argument that prints the position of the first space and the last space of the given String s.
Example:
Input value of s = "Cloud computing means Internet based computing"
Output:
First index: 5
Last Index: 36
void Joystring(String s1, String s2) with two string arguments that combines the two strings with a space between them and prints the resultant string.
Example:
Input value of s1 = "COMMON WEALTH"
Input value of s2 = "GAMES"
Output: COMMON WEALTH
You are very cute
Answer:
import java.util.*;
class Sample
{
static void print(int x , int y)
{
int difference = (x*x) - (y*y);
System.out.println("The difference of the squares of " + x + " and " + y + " is " + difference);
}
}
public class Main
{
public static void main(String[] args) {
int i = 9;
int j = 8;
Sample.print(i , j);
}
}
Explanation: