Consider the following methods’ headers:
public static int one(int a, char b, double c, String d)
public static double two(double x, double y)
public static char three(int r, int s, char t, double u)
Answer the following questions:
|
Q1) What is the signature of method one? Answer: |
|
Q2) What is the return type of method two? Answer: |
|
Q3) What the formal parameters of method three? Answer: |
|
Q4) How many actual parameters are needed to call the method three? Answer: |
|
Q5) Write a statement that prints the value returned by method two with the actual parameters 17.5 and 18.5, respectively. Answer: |
|
Q6) Write a return statement in method three that returns the value of variable t. Answer: |
1.
The method signature is part of the method declaration. It's the combination of the method name and the parameter list.
ANS: The signature for method 1: one(int, char, double, String )
2.
You declare a method's return type in its method declaration. Within the body of the method, you use the return statement to return the value. Any method declared void doesn't return a value.
ANS: double
3.
Formal Parameter: A variable and its type as they appear in the prototype of the function or method.
ANS: int r, int s, char t, double u
4.
Actual Parameter: The variable or expression corresponding to a formal parameter that appears in the function or method call in the calling environment.
ANS: 4 actual parameters are needed to call the method three
5.
for printing the returned value of method two following syntax can be used:
ANS: System.out.printf("%f \n", two(17.5,18.5));
6.
for returning t in method 3, following syntax can be used:
ANS:
public static char three(int r, int s, char t, double u)
{
return t;
}
Consider the following methods’ headers: public static int one(int a, char b, double c, String d)...
Consider the following method: public static int mystery (int x, double y, char ch) { int u; if ('A' <= ch && ch <= 'R') return (2 * x + (int)(y)); else return((int)(2 * y) - x); } What is the output of the following Java statements? a. System.out.println (mystery(5, 4.3, 'B')); b. System.out.println (mystery(4, 9.7, 'v')); c. System.out.println (2 * mystery(6, 3.9, 'D'));
1. Answer the questions considering the following functions headers: int func1(int x, double w) double func2(string I, int y, double r) char func3(int z, int s, double t, char a) a. How many parameters does function func1 have? What is the type of function func1? b. How many parameters does function func2 have? What is the type of function func22 c. How many parameters does function func3 have? What is the type of function func3? d. Write a C++ statement...
public static int countCharacter(String str, char c) { // This recursive method takes a String and a char as parameters and // returns the number of times the char appears in the String. You may // use the function charAt(int i) described below to test if a single // character of the input String matches the input char. // For example, countCharacter(“bobbie”, ‘b’) would return back 3, while // countCharacter(“xyzzy”, ‘y’) would return back 2. // Must be a RECURSIVE...
Given following method, public static double getQuotient (int num1, int num2){ return num1/(double) num2; } Write Java statement to invoke the method.
How can i print a diamond implementing these methods public static void printNChars(int n, char c)). This method will print n times the character c in a row, public static void printDiamond(int size, char edgeChar, char fillChar). This method will call printNChars() method to print the shape. It will use the edgeChar to print the sides and the fillChar to fill the interior of the shape. The shape will have a height and a width of the given size. public...
Write the following Java program: public static String getFlag(int size, char color1, char color2, char color3) - This method returns a string where a triangle appears on the left size of the diagram, followed by horizontal lines. For example, calling DrawingApp.getFlag(9, 'R', '.', 'Y'); will generate the string: R............................................ RRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRRRR.................................... RRRRRRRRR.................................... RRRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY R............................................ The diagram has a number of rows that corresponds to size * 2 and...
What is the signature of the following method? public int doSomething(int a, double b, String c) { System.out.print(a+b+c); }
Here is the indexOf method that I wrote: public static int indexOf(char[] arr, char ch) { if(arr == null || arr.length == 0) { return -1; } for (int i = 0; i < arr.length; i++) { if(arr[i] == ch) { return i; } } return -1; ...
Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the Maximum of the 2 values Write a public static method named getMinOf2Ints that takes in 2 int arguments and returns the Minimum of the 2 values Write apublic static method named getMaxOf3Ints that takes in 3 int arguments and returns the Maximum of the 3 values Write a public static method named getMedianOf3Ints that takes in 3 int arguments and returns the Median Value...
public static String getFlag(int size, char color1, char color2, char color3) - This method returns a string where a triangle appears on the left size of the diagram, followed by horizontal lines. For example, calling DrawingApp.getFlag(9, 'R', '.', 'Y'); will generate the string: R............................................ RRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRRRR.................................... Write a Java program and the result has to match the pattern which showed above.