1. Determine the output of the following Java program. Notice that the method fe
ID: 3670537 • Letter: 1
Question
1. Determine the output of the following Java program. Notice that the method fen2 ) is overloaded, so there are really three distinct functions here // Probleml.java class Probleml( public static void main( String args ) int a=5, b-3, double x-2.2, c; y=1.3, z; c- fcnl (a, b) b= fcn2(x, y) ; z - fcn2 (c, b) System.out .println ("a= " +at", system . out .printIn("x= " +x+", System.out.println("bye!"); b="+bt", y="ty+", c-c); z-+2); static int fcnl (int i, int j)l int k (i++) return k+2; + (++) ); static int fen2 (double u, double v)I return fcnl ( (int) (utv), 3) static double fcn2 (int r, int s) return (double) fcnl (rts, 3); 2. Fill in the definition of function concatenate () below. This function takes as input two int arrays A and B, of any length, and returns a new int array which is the concatenation of A and B, i.e. the length of the returned array is the sum of the lengths of A and B, and the contents of the returned array are the values in A followed by the values in B static int[] concatenate (int[] A, int[] B) // your code starts here ) // your code ends hereExplanation / Answer
1) Output of the First program
a=5, b=9, c=11
x=2.2, y=1.3, z=26.0
Bbbyeee
2)
public static int[] Concatenate(int [] A,int [] B)
{
int k=0;
int []c=new int[25];
for (int i = 0; i < A.length; i++) {
c[k++]=A[i];
}
for (int j = 0; j < B.length; j++) {
c[k++]=B[j];
}
return c;
}
3)
f(7)
f(6)
f(5)
f(4)
f(3)
f(2)
f(1)
28
4)
static int sum(int n)
{
if(n!=0)
return n+sum(n-1); /* recursive call */
}
5)
-22
5
3
-3
2
19
2
5
4
-1
6)
Blahh [foo=15, bar=3.5]
Blahh [foo=15, bar=0.0]
false
7)
public class GetMAxAndMin {
static int GetIndexMax(int [] a)
{
int index = 0;
int max=a[0];
for (int i = 0; i < a.length; i++) {
if(a[i]>max)
{
max=a[i];
index=i;
}
}
return index;
}
static int GetIndexMin(int [] b)
{
int index = 0;
int min=b[0];
for (int i = 0; i < b.length; i++) {
if(b[i]<min)
{
min=b[i];
index=i;
}
}
return index;
}
public static void main(String[] args) {
int [] list={3,9,6,12,23,-25,54,9,0,-12,27};
System.out.println("MAx index is "+GetIndexMax(list));
System.out.println("Min index is "+GetIndexMin(list));
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.