0
What is the output and why? public static int[] make (int n){ int[]a=new int [n]; a [i]=i+1; } return a; } public static void dub (int []jub){ for (intent i=0;i <jub.length;i++){ jub*=2; } } public static int mus (int []zoo){ int jus=0; for (int i=0;i <zoo.length;i++){ jus+=zoo [i]; } return jus; } public static void main (String [] args){ int [] bob =make(5); dub (bob); System.out.println (mus (bob)); }
2 Respostas
+ 1
Code is missing 2things. Make method needs a value for i. Dub method needs a return and that end line needs to be fixed.
But, let's pretend i = 0. Answer would be 15. Muss(bob). Bob = make with value 5. In make, int a array will be given 5 as it's index. if i = 0 that would make a[0] = 0 + 1, onwards up to a[4] = 4 + 1. make gets put into bob. now we go to muss. muss cycles through zoo array(which is bob) and adds each value to jus.1 + 2 + 3 + 4 + 5 = 15. That's it. dub method gets called but returns nothing so it doesn't matter here. If it did, you'd take each number * by 2 then add them all together. Answer would be 30 in that case.
0
Thanks