Mystery Method 1 This method performs a useful task with a collection of integers, but we've hidden its name so you have to work out what that is. What does it do? 1 public static boolean ???(int[] data, int val) { //Note: ??? isn't a valid name boolean outcome - false; int i -e; 2 3 4 5 6 7 8 9 10 11 12 13 ) while (i < data. length 88 loutcome) { if (data[1] val) outcome true; } i++; return outcome; Trace the execution of the method if it were called with the following parameter values (that is, create two tracing tables, one for each run) to see if you can work out what it does. Include the following summary table after your traces to record the outcomes. Value returned val data 3 (0,8,1,3,-2) 2 [1.-5,6,8,-4) Provide a name for this method with your two tracing tables,
Mystery Method 2 The method below performs another useful task with an array of int values. Demonstrate how it is executed in the computer by creating two tracing tables, one for each sample input, then suggest a valid method name that describes its purpose 1 2 3 public static int ???(int[] data) { int answer - 10000; 4 5 6 7 8 9 10 11 ) for (int 1 - 0; i < data.length; i++) if (data[1] < answer) answer - data[1]: > 3 return answer; Trace the execution of the method if it were called with the following parameter values (that is create two tracing tables, one for each run) to see if you can work out what it does. Include the following summary table after your traces to record the outcomes Value returned data (50,25, 15,40 [10, 14,5,6,2)
Code Sample 3 Create a tracing table for the following code: 1 String[] names - {"Hiccup", "Toothless", "Astrid", "Stormfly" ); 2 3 System.out.println("Kids like these + names.length + story characters:"), for (int 1 - 0; i < names.length; 1++) ( 5 System.out.println(names[1]); 6) 4 Code Sample 4 Create a tracing table for the following code. It may look confusing as a whole, so work through it methodically line by line, paying careful attention to the loop Initialisation update and test: 1 int[] sequence - { 7, 8, 9]; 2 int end - sequence, length - 1; 3 int temp 4 5 temp- sequence[end]; 6 for (int i = end; i > 0; i--) { 7 sequence [1] - sequence[i - 1); 8 ) 9 sequence[@] - temp; At the end, sketch the array's contents as illustrated above
Mystery Method 1 This method performs a useful task with a collection of integers, but we've hidden its name so you have
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Mystery Method 1 This method performs a useful task with a collection of integers, but we've hidden its name so you have
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!