1.In the first question, you will read some code and write a concise, high-level, English description of the code’s action. Here is an example:
(1)
double mystery(int[] a) {
if (a.length == 0) {
return 0.0;
}
double x = 0.0;
for (int i: a) {
x += i;
}
return x / a.length;
}
(2)
int mystery(char c, String s) {
int x = 0;
for (char k : s.toCharArray()) {
if (c != k) {
x++;
}
}
return x;
}
2.In the second question, you’ll identify a logic error in a short snippet of code. That is, you will find a conceptual error, not an error that the compiler would catch. Here is an example:
(1)
/** Return the mean of the values stored in `a`. */
double mean(int[] a) {
if (a.length == 0) {
return 0.0;
}
double x = 0.0;
for (int i = 0; i < a.length; i++) {
x += i;
}
return x / a.length;
}
3.
In the final question, you will write a short class or method according to a textual description. For example, a question might state:
Define a class Dog. A Dog instance has a name (which could change), a breed (which is immutable, that is, it cannot change) and a licenseNumber (an integer between 1 and 1,000,000, which is immutable). Two Doginstances are considered equal if and only if their licenseNumbers are equal.
Your definition should include the constructor and the equals method, but should elide the getters and setters.
Another question might state:
Write a method which, given two int arrays, determines whether the values in the first array a are a subset of the values in the second array b. In other words, return true if and only if every value in a is also present in b. Your method should have the signature boolean isSubset(int[] a, int[] b).
1(1) Code finds the average of the numbers in the
array
Explanation
x has the sum of the numbers in the array
1(2) Counting the characters which are not the given
character.
Example mystery('e', "ellen") givesn 3 because 2 are e's only
Note: One
question at a time please -- Policy of Chegg
1.In the first question, you will read some code and write a concise, high-level, English description...
What is the output of this code segment? double [] a = {-1.2, 3.1, -4.7, 38.0, 0.0}; double temp = a[0]; for (int i = 1; i < a.length; i++) { if (a[i] < temp) { temp = a[i]; } } System.out.println (temp); What does this method do? In one short English sentence describe the task accomplished by this method. public static int foo(int [] a) { int temp = 0; for (int i = 0; i < a.length; i++)...
need help editing or rewriting java code, I have this program
running that creates random numbers and finds min, max, median ect.
from a group of numbers,array. I need to use a data class and a
constructor to run the code instead of how I have it written right
now. this is an example of what i'm being asked
for.
This is my code:
import java.util.Random;
import java.util.Scanner;
public class RandomArray {
// method to find the minimum number in...
write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...
1.Write code for a Java method, printArray, that takes an int array as parameter and prints it out, one element per line. public static void printArray (int[] values){ Methods that do NOT return a result have “void” as return type. Notice how an array parameter type is passed, int [] }// end printArray 2.Write code for a Java method that takes in as input parameter an integer number, say num, and returns a double array of size num with all...
1. Write a complete program based on public static int lastIndexOf (int[] array, int value) { for (int i = array.length - 1; i >= 0; i--) { if (array [i] == value) { return i; } } return -1; write a method called lastindexof that accepts an array of integers and an integer value as its parameters and returns the last index at which the value occurs in the array. the method should return -1 if the value is...
Please answer both questions. Thanks
Question 24 (1 point) What value would be returned if the method mystery were called and passed the array values (1, 15, 37, 12) as its parameter? public static int mystery (int[] list) int x = 0; for (int i = 1; i < list.length; i++) { int y = list[i] - list [0]; if (y > x) x = Y } } return x; 29 35 1 36 Question 25 (1 point) What is...
Please help me to answer the 5 programming questions and give
some specific explanations, thanks a lot !!!
Question 5 In the following method, describe which variables are thread-safe and which are not thread-safe and why. Not yet answered public int wasSoHard (int x, String in, Array List<Integer> stuff) { Marked out of char c in.charAt (x) 3.00 P Flag question for (int i= 0; i < in.length); i if (in.charAt (i) == c) { stuff.add (i); return stuff .size()...
Valentine’s Day Question(JAVA) Suppose you had a list with 30 valentines and you stored their names in an array (you hopeless romantic). Then if you had 5 people ask to be your valentine, you would need to make a new array of size 35 (30 + 5) and copy over the original valentines before being able to add the new valentines to the array. This question uses the same logic. Write a program that has a method called doubleSize. The...
C programming lab: Description: In this lab you will write a program that will contain two functions, setlsbs() and getlsbs(). These functions will use bitwise operators to embed and extract "hidden" bits in a character array. Write a program to test your functions as follows: Obtain a random number seed from the command line of your program using command line arguments. Initialize an array p of 8 unsigned char with random numbers from 0 to 255 Initialize a separate unsigned...
Q1) How would you declare an array of doubles called myDoubles? Arrays can be initialized in one of two ways. In one method, the array elements are placed in a list enclosed in curly braces after the array name definition. For example, the code below creates an array of ints with 3 elements: 1, 2 and 3. int[] a = {1, 2, 3, 4}; We can also initialize an array with a new construct, indicating how many elements we want...