// Filling out the boxes for copying the values and then printing the target array using for loop.
Public static void main(String args[])
{
double[] target = new double[3];
double[] source = {1.0, 5.5, 7.9};
int loopIndex;
for (loopIndex=0; loopIndex<3; loopIndex++){
/* copying the content from source to target */
target[loopIndex] = source[loopIndex];
}
target[0] = 2.0;
target[1] = 4.5;
/* Printing the values stored in target array */
loopIndex = 0;
for (loopIndex=0; loopIndex<3; loopIndex++){
System.out.println(target[loopIndex]);
}
}
the box (Follow the instruction in the 13. Study the following code and then fill in...
Directions: Follow the instructions below to explore sorting objects using boxes below. You will sort the boxes by the largest volume. Copy and Paste the Box method below into BlueJ public class Box { private double length, height, depth; public Box( double length, double height, double depth ) { this.length = length; this.height = height; this.depth = depth; } public double volume() { return length*height*depth; } // compare this Box to another Box int compareTo( Box other )...
2. Write a counter controlled loop to solve the following problems. Each one will involve an array (MinMax.java) Read in 25 ints from the keyboard, and store them in an array. Then, find the maximum and minimum values in such an array, and display them on the screen. public class Array-Assignment { public static void main(String [] args) { int [] x = new int[3]; int [] y = {3, 5, 9, 2}; x[2] = y[3]; ...
With the following code answer the following questions. describe what happens when the following code is executed: String[] searchMe = {"apple","bear","cat","dog","elephant"}; describe what is being created when this statement executes System.out.println(linearFind("cat",searchMe)); describe the values passed to the method describe how each of the specific values are compared to each other describe when the method stops executing and/or when the loop stops executing describe what is returned to beoutprinted System.out.println(binaryFind("apple",searchMe)); describe the values passed to the method describe how each of...
Computer Science - Java
Explain the code step by step (in detailed order). Also explain
what the program required. Thanks
7 import java.io.File; 8 import java.util.Scanner; 9 import java.util.Arrays; 10 import java.io.FileNotFoundException; 12 public class insertionSort 13 14 public static void insertionSort (double array]) 15 int n -array.length; for (int j-1; j < n; j++) 17 18 19 20 21 double key - array[j]; int i-_1 while ( (i > -1) && ( array [i] > key array [i+1] -...
Fill in the find method and numMale method public class ComparableDemo { public void init(Object arr[]) { arr[0] = new Employee("Abby", 3000, 1, null, 'f'); arr[1] = new Employee("John", 2000, 2, (Employee)arr[0], 'm'); arr[2] = new Employee("Tim", 2000, 2, (Employee)arr[0], 'm'); arr[3] = new Employee("Tony", 1000, 3, (Employee)arr[0], 'm'); } //this method finds and returns the Employee object in the array whose name equals to //the...
Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array double[10]; c. charl charArray "Computer Science"; None of the above Analyze the following code: class Test public static void main(Stringl] args) System.out.println(xMethod(10); public static int xMethod(int n) System.out.println("int"); return n; public static long xMethod(long n) System.out.,println("long"); return n The program displays int followed by 10 The program displays long followed by 10. The program does not compile. None of the above. tions 3-4 are...
1. What is the output when you run printIn()? public static void main(String[] args) { if (true) { int num = 1; if (num > 0) { num++; } } int num = 1; addOne(num); num = num - 1 System.out.println(num); } public void addOne(int num) { num = num + 1; } 2. When creating an array for primitive data types, the default values are: a. Numeric type b. Char type c. Boolean type d. String type e. Float...
6. (4 points) The following code for insertion sort has been modified to print out the sorted component of the array during the sort. What will be the output of running the main method of the following code? Try to trace by hand and then verify by executing the code public class Insertion ( public static void sort (String[] a) f int n- a.length; for (int i-1; i < n; i++) f for (int j i; j 0; j--) if...
last question : Don't be negative
and source Code : of don't be negative
Repeat the assignment "don't be so negative" except solve the problem using recursion. Specifically, create an array of 10 random integers between -10 and +10 then create a method say "findNegatives" that takes as input parameters the array, and possibly other parameters, then calls itself (direct recursion); method find Negatives( ...method parameters here...) ...some stopping criteria... find Negatives(...method parameters here...) Output: Array position #0 #1 Value...
In the code shown above are
two parts of two different exercises. HOW WE CAN HAVE BOTH OF THEM
ON THE SAME CLASS BUT SO WE CAN RECALL them threw different
methods. Thank you.
1-First exercise
import java.util.Scanner;
public class first {
public static int average(int[] array){
int total = 0;
for(int x: array)
total += x;
return total / array.length;
}
public static double average(double[] array){
double total = 0;
for(double x: array)
total += x;
return total /...