Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please explain the following methods in details public class Task1 { public static void main ( String[] args ) { double [] nums1d = {
Please explain the following methods in details
public class Task1 { public static void main(String[] args) { double[] nums1d = {1, 3}; double[][] nums1 = {{1, 2}, {3, 4, 5}, {6}}; double[][] nums2 = {{4, 6}, {12, 4, 5}, {6}}; String str = "abc"; String[] str2 = {"Hello", "World"}; String[][] str3 = {{"Hello", "World"}, {"Welcome", "to", "Java"}}; } /** * This method calculates max double in 2d array * * @param nums1 {{1,2},{3,4,5},{6}} * @return max {6} */ public static double max(double[][] nums1) { double max = 0; for (double[] nums : nums1) { for (double num : nums) { if (num > max) { max = num; } } } return max; } /** * This method calculates max double of each row * * @param nums1 {{1,2},{3,4,5},{6}} * @return maxRow {2,5,6} */ public static double[] maxRow(double[][] nums1) { double[] maxRow = new double[sumRow(nums1).length]; double idx = 0; for (int i = 0; i < sumRow(nums1).length; i++) { for (double num : nums1[i]) { if (num > idx) { idx = num; } } maxRow[i] = idx; idx = 0; } return maxRow; } /** * This method calculates max double of each column * * @param nums1 {{1,2},{3,4,5},{6}} * @return maxCol {6,4,5} */ public static double[] maxCol(double[][] nums1) { double[] maxCol = new double[sumCol(nums1).length]; double idx = 0; for (int i = 0; i < sumCol(nums1).length; i++) { for (double[] nums : nums1) { if (nums.length > i) { if (nums[i] > idx) { idx = nums[i]; } } } maxCol[i] = idx; idx = 0; } return maxCol; } /** * This method counts the number of vowels in a string * * @param str ["abc"] * @return no of vowels {1} */ public static int countVowels(String str) { int vowels = 0; for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); Character.toUpperCase(ch); if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') { vowels++; } } return vowels; } /** * This method counts the number of vowels in a 1d string array * * @param str2 {"Hello", "World"} * @return no of vowels in 1d array {3} */ public static int countVowelsArray(String[] str2) { int vowels = 0; for (String word : str2) { countVowels(word); vowels += countVowels(word); } return vowels; } /** * This method counts the number of vowels in a 2d string array * * @param str3 {"Hello", "World"}, {"Welcome", "to", "Java"} * @return no of vowels in 2d string {9} */ public static int countVowelsTwoDArray(String[][] str3) { int vowels = 0; for (String[] words : str3) { countVowelsArray(words); vowels += countVowelsArray(words); } return vowels; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started