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 entries in the array initialized to 3.0.
public static double[] arrayDouble (int num) {
Note the return type of this method: it is double[]
indicating that an array of type double is to be returned
What is the printArray? Can you explain this question? Thank you!
//printArray prints out the input array elements one element per line.
public static void printArray (int[] values){
for(int i = 0;i<values.length;i++){
System.out.println(values[i]);
}
}
public static double[] arrayDouble (int num) {
double res[] = new double[num];
for(int i = 0;i<num;i++){
res[i] = 3.0;
}
return res;
}

1.Write code for a Java method, printArray, that takes an int array as parameter and prints...
Write a program that stores a phrase as an array of words, and then prints it backwards. The main method calls method getInput , which asks the user how many words there are, stores them in an array, and returns this array. printBackwards then takes this array of words, and prints it in reverse. Code Example: import java.util.Scanner; public class L17Num1{ public static void main(String[] args) { String[] sArray=getInput(); printBackwards(sArray); } public static String[] getInput() { System.out.println("How many...
Write a method named printReverse() that accepts an int array as its parameter and prints that array in reverse order. This method should not have a return statement (void). - All elements should be printed on the same line, separated by a space - A new line should be printed after the entire array prints - If the array passed in held the values: {3,2,1} - Output: 1 2 3 //newline printed here
Write the definition of a method printArray, which has one parameter, an array of ints. The method does not return a value. The method prints out each element of the array, on a line by itself, in the order the elements appear in the array, and does not print anything else.
Write a static method called printWithSpaces that takes a String as its parameter and prints the characters of the string separated by spaces. For example: > Methods.printWithSpaces("method") m e t h o d You should have a single space after the last character. This method should not return a value. That is similar to this code for printing the string vertically public static void printVertical(String s) { for (int i = 0; i < s.length(); i++) { char c =...
Write a Java method that should take an ArrayList as a parameter, print its element in the reverse order. The main function that calls the method is the following: import java.util.*; public class ReverseGen { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("How many numbers do you want to input?"); int num = input.nextInt(); ArrayList<Double> d = new ArrayList<Double>(num); for(int i = 0 ; i < num; i++){ System.out.print("Enter...
1) Write a public static method named printArray, that takes two arguments. The first argument is an Array of int and the second argument is a String. The method should print out a list of the values in the array, each separated by the value of the second argument. For example, given the following Array declaration and instantiation: int[] myArray = {1, 22, 333, 400, 5005, 9}; printArray(myArray, ", ") will print out 1, 22, 333, 400, 5005, 9 printArray(myArray,...
/** * Write a method named outOfOrder that takes as a parameter an array of double and returns a value of type int. * This method will test the array for being out of order, meaning that the array violates the conditions: * array[0] <= arrayValues[0] <= arrayValues[2] <=... * * The method returns -1 if the elemnts are not out of order; otherwise , it returns the index of the first element of the array that is out of...
X43: countEvens Write a function in Java that takes an int array as its parameter and returns the number of even ints it contains. Note: the % "mod" operator computes the remainder, e.g. 5 % 2 is 1. Complete the code bellow. Complete the code below. Use: logic conditionals if arrays loops mod public int countEvens(int[] nums) { }
JAVA Code: Complete the method, sumOdds(), below. The method takes in an array of integers, numbers, and returns the sum of all the odd numbers in the array. The method should return 0 if the array contains no odd numbers. For example, if the given array is [12, 10, 5, 8, 13, 9] then the method should return 27 (5+13+9=27). Starter Code: public class Odds { public static int sumOdds(int[] numbers) { //TODO: complete this method } }
JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a parameter. This method calculates and returns the largest even number in the list. If there are no even numbers in the array, the method should return 0. You can assume that the array is not empty. For example: Test Result int[] values = {1, 4, 5, 9}; System.out.println(getMaxEven(values)); 4 System.out.println(getMaxEven(new int[]{1, 3, 5, 9})); 0 public static int --------------------------------------------------------------------------------- 2. Write a static method...