Java Write a static method that finds the minimum of 2 integ
Java
Write a static method that finds the minimum of 2 integers and returns the minimum integer if
the min is less than 5, else it returns 0. (skip writing a class and main, only write the method)
Write a static method to count odd numbers in String array, return the count.
(skip writing a class and main, only write the method)
5. Strings
Basic methods and operations.
6. Math
Hint: random()
7. Scanner
Demo the Scanner class.
8. JOptionPane
Demo the JOptionPane class.
10. Conditionals
12. Conditional Operators
13. Bits
Use of & | ^ ~ << >> operators and how to set/unset bits.
17. Classes
Solution
1)
public static int findMinimum(int x, int y){
int min = x; // initializing min with x value
if(min > y)
min = y;
if( min < 5)
return min;
else
return 0;
}
2)
public static countOdd(String[] arr){
int odd = 0;
// iterating through all elements of arr
for(int i=0; i<arr.length(); i++){
// converting in to Intger
int d = Integer.parseInt(arr[i]);
// if odd, then increment count
if(d %2 == 1)
odd++;
}
return count;
}

