Create a program SimpleMethod.java with method maxMinSumSquareRt() that takes three…
- User
Create a program SimpleMethod.java with method maxMinSumSquareRt() that takes three double values as arguments, calculates the sum of the largest and smallest value and returns the square root of the sum. In your method you can use methods of the class Math. Run (main method) the method maxMinSumSquareRt(double a, double b, double c) in the same class with three parameters of your choice and print out the result on the command line. write it shortly please without scanner
- Assistant
Here is the code for the SimpleMethod.java program:
javapublic class SimpleMethod { public static void main(String[] args) { double a = 5.5; double b = 8.2; double c = 3.7; double result = maxMinSumSquareRt(a, b, c); System.out.println("Result: " + result); } public static double maxMinSumSquareRt(double a, double b, double c) { double max = Math.max(Math.max(a, b), c); double min = Math.min(Math.min(a, b), c); double sum = max + min; double squareRoot = Math.sqrt(sum); return squareRoot; } }The program defines a method that takes three double values as arguments. Inside the method, it calculates the maximum and minimum value using the and methods. Then, it calculates the sum of the maximum and minimum value and stores it in the variable . Finally, it calculates the square root of the sum using the method and returns the result.
- User
Write a program AllValuesTrueInArray.java with a method isAllTrue(boolean[] values) that checks if all values in a boolean array are true and returns true if that is the case, false if it is not. Run and test your program. without scanner and shortly please
- Assistant
Here is the code for the AllValuesTrueInArray.java program:
javapublic class AllValuesTrueInArray { public static void main(String[] args) { boolean[] values = {true, true, true, true}; boolean result = isAllTrue(values); System.out.println("Result: " + result); } public static boolean isAllTrue(boolean[] values) { for (boolean value : values) { if (!value) { return false; } } return true; } }The program defines a method
isAllTrue()that takes a boolean array as an argument. Inside the method, it iterates over each element in the array using a for-each loop. If any value is false, it immediately returns false. If all values are true, it returns true.In the
main()method, a boolean arrayvaluesis declared and initialized with some values of your choice. TheisAllTrue()method is called with this array, and the result is printed on the command line. - User
Create a program VowelCount.java that contains a method countVowels(String text) that to count the number of vowels in a String. You can use the method charAt() of the class String if a certain character in the String is a vowel. Run and test your program. please write it shortly
- Assistant
Here is the code for the VowelCount.java program:
javapublic class VowelCount { public static void main(String[] args) { String text = "Hello World"; int count = countVowels(text); System.out.println("Number of vowels: " + count); } public static int countVowels(String text) { int count = 0; String vowels = "aeiouAEIOU"; for (int i = 0; i < text.length(); i++) { char ch = text.charAt(i); if (vowels.indexOf(ch) != -1) { count++; } } return count; } }