I need java code for the following problem.
Please find the answer below, I have mentioned all the details in the comments:
Main.java public class Main { public static void main(String[] args) { //test for all the methods System.out.println("Test for cubeIt"); System.out.println("return value of cubeIt(2): " + Numbers.cubeIt(2)); System.out.println("return value of cubeIt(3): " + Numbers.cubeIt(3)); System.out.println(); System.out.println("Test for randomInRange"); System.out.println("return value of randomInRange(2): " + Numbers.randomInRange(10,20)); System.out.println("return value of randomInRange(2): " + Numbers.randomInRange(1,5)); System.out.println(); System.out.println("Test for countA"); System.out.println("return value of countA(\"RANDOM\"): " + Characters.countA("RANDOM")); System.out.println("return value of countA(\"ABCABCAA\"): " + Characters.countA("ABCABCAA")); System.out.println(); System.out.println("Test for countA"); System.out.println("return value of multiConcat(\"hi\",3): " + Characters.multiConcat("hi",3)); } } class Numbers{ public static int cubeIt(int x){ //returnt the x^3 using pow method return (int)Math.pow(x,3); } public static int randomInRange(int min,int max){ int val; //get the value using Math.Random() val = min + (int)(Math.random() * ((max - min) + 1)); return val; } } class Characters{ public static int countA(String val){ int count = 0; //count each character by comparing it with the 'A' for (int i=0; i<val.length(); i++) { // checking character in string if (val.charAt(i) == 'A') count++; } return count; } public static String multiConcat(String s, int count){ //get the string builder object StringBuilder sb = new StringBuilder(); while(count-- > 0){ //conacat for count times sb.append(s); } //return string value return sb.toString(); } }
Output:
I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...
By using Java public static methods solve following problem Write a method called vowelCount that accepts a String as its only parameter, and returns an array int[5] containing the count of vowels a,e,i,o,u in that String, using ignoreCase. For example, vowelCount("") returns {0,0,0,0,0}, and for the callvowelCount("Bill Iverson") your method returns {0,1,2,1,0} because there is one 'e' and two 'i' vowels (ignore case) and one 'o' with zero counts for 'a' and 'u' vowels.
Please show screenshot outputs and fully functional code for the Java programs. Question 1: Write a method that computes and returns the area of a square using the following header: public static double area ( double side) Write a main method that prompts the user to enter the side of a square, calls the area method then displays the area. Question 1a: Write a method that converts miles to kilometers using the following header: public static double convertToKilometers (double miles)...
Submit Chapter7.java with four (4) public static methods as follows: A. Write a method called mostCommon that accepts an array of integers as its only parameter, and returns the int that occurs most frequently. Break ties by returning the lower value For example, {1,2,2,3,4,4} would return 2 as the most common int. B. Write mostCommon (same as above) that accepts an array of doubles, and returns the double that occurs most frequently. Consider any double values that are within 0.1%...
Write a complete Java program called MethodTest according to the following guidelines. The main method hard-codes three integer values into the first three positions of an array of integers calls a method you write called doubleEachValue that takes an array of integers (the one whose values you hard-coded in main) as its only argument and returns an ArrayList of integers, with each value in returned ArrayList equal to double the correspondingly indexed value in the array that is passed in...
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...
Write a java Program Initialize Array. Write a Java method initArray() with the following header to initialize a one-dimensional array a such that the element values (integers) are twice the index value. For example, if i = 23, then a23 = 46. The function is void with one parameter -- the integer array of a[]. Then write a main() with an int[] array2i size 100 to call
In Java write the following array- processing methods into the same application, Lab13.java. Use the main method in this application to test your methods. 1) Write the void method, shiftLeft, which accepts an array of int and changes the elements of this array so that the index of each element is now less by one and the last element of the array is now zero. For example, if the parameter array is {7, 3, 2, 9, 5}, then when this...
Write four overloaded methods called randomize. Each method will return a random number based on the parameters that it receives: randomize() - Returns a random int between min and max inclusive. Must have two int parameters. randomize() - Returns a random int between 0 and max inclusive. Must have one int parameter. randomize() - Returns a random double between min and max. Must have two double parameters. randomize() - Returns a random double between 0 and max. Must have one...
3. Write Java methods to accomplish each of the following Write a method named simpleAry which accepts and return nothing. It creates an array that can hold ten integers. Fill up each slot of the array with the number 113. Then, display the contents of the array on the screen. You must use a loop to put the values in the array and also to display them. Write a method named sury which accepts an array of type double with...
Write a Java program that has a method called arrayAverage that accepts an arrary of numbers as an argument and returns the average of the numbers in that array. Create an array to test the code with and call the method from main to print the average to the screen. The array size will be from a user's input (use Scanner). - array size = int - avergage, temperature = double - only method is arrayAverage Output: