code:
class Chegg{
public static int getMaxOf2Ints(int a,int b)
{
return a>b?a:b;
}
public static int getMinOf2Ints(int a,int b)
{
return a<b?a:b;
}
public static int getMaxOf3Ints(int a,int b,int c)
{
if(a>b&&a>c)
return a;
else if(b>c)
return b;
return c;
}
public static void printMinOf3Ints(int a,int b,int c)
{
if(a<b&&a<c)
System.out.println("The min is
"+a);
else if(b<c)
System.out.println("The min is
"+b);
System.out.println("The min is "+c);
}
public static int getMedianOf3Ints(int a,int b,int c)
{
int x = a-b;
int y = b-c;
int z = a-c;
if(x*y > 0) return b;
if(x*z > 0) return c;
return a;
}
public static int getProdOfAllPositiveInts(int n)
{
int prod=1;
for(int i=1;i<=n;i++)
prod*=i;
return prod;
}
public static int getProdOfAllNegativeInts(int n)
{
int prod=1;
for(int i=-1;i>=n;i--)
prod*=i;
return prod;
}
public static int getCharAtIndex(String s,int index)
{
return s.charAt(index);
}
public static String getStringReversed(String s)
{
return new
StringBuilder(s).reverse().toString();
}
public static String getStringTitleCased(String s)
{
char c[]=s.toCharArray();
c[0]=Character.toUpperCase(c[0]);
for(int i=0;i<c.length-1;i++)
{
if(c[i]==' ')
{
c[i+1]=Character.toUpperCase(c[i+1]);
}
}
return new String(c);
}
public static void main(String args[])
{
System.out.println("The max of 3,5 is
"+getMaxOf2Ints(3,5));
System.out.println("The min of 3,5 is
"+getMinOf2Ints(3,5));
System.out.println("The max of 3,4,5 is
"+getMaxOf3Ints(3,4,5));
printMinOf3Ints(3,4,5);
System.out.println("The median of 3,6,5 is
"+getMedianOf3Ints(3,6,5));
System.out.println("The prod is 1 to 5
"+getProdOfAllPositiveInts(5));
System.out.println("The prod is -1 to -5
"+getProdOfAllNegativeInts(-5));
System.out.println("The character at index 3 is
"+(char)getCharAtIndex("Ezhil",2));
System.out.println("The character at index 3 is
"+getStringReversed("Ezhil"));
System.out.println("The character at index 3 is
"+getStringTitleCased("sushmanth ezhil"));
}
}
Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the...
Write a static method named middleValue that takes three int arguments, and returns an int. When given three different argument values, the method should return the value that is numerically between the other two values. When given three values where two or more argument values are the same, then the function should return that value. Examples: middleValue(1, 2, 3) will return 2 middleValue(5, 2, 7) will return 5 middleValue(8, 4, 6) will return 6 middleValue(1, 2, 1) will return 1...
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...
public static int countCharacter(String str, char c) { // This recursive method takes a String and a char as parameters and // returns the number of times the char appears in the String. You may // use the function charAt(int i) described below to test if a single // character of the input String matches the input char. // For example, countCharacter(“bobbie”, ‘b’) would return back 3, while // countCharacter(“xyzzy”, ‘y’) would return back 2. // Must be a RECURSIVE...
Write a static method named sumOf that takes an array of int values as an argument (you may safely assume that the array contains at least 1 element). This method should return the sum of all values in the array. Examples: Given the following array declaration and definition. int[] theArray = {0, 0, 0, 0, 0, 0}; sumOf(theArray) will return 0 Given the following array declaration and definition. int[] theArray = {1, 1, 1, 1, 1, 1}; sumOf(theArray) will return...
Write a cell method that takes a single double as an argument and returns an int. The int should be the next highest whole integer (eg 3.14 would return 4). Use math not built-in Java methods mins) Write a method that takes a string as an argument. It your string is more than 10 letters or less than 1 letter return "Bad number". Otherwise, return the telephone number equivalent of the input. Your return can be of type String Eg...
Write a ceil method that takes a single double as an argument and returns an int. The int should be the next highest whole integer (eg 3.14 would return 4). Use math, not built-in Java methods (est. 20 mins) Write a method that takes a string as an argument. If your string is more than 10 letters or less than 1 letter return "Bad number." Otherwise, return the telephone number equivalent of the input. Your return can be of type...
Create a public static method named valueG that takes an ArrayList of type Double and returns a double. This method returns the maximum result ( do not return the original value) of taking the sine of each value from the input
5)Write a public static void method named happyNewYear that takes in an int and does the following: ● prints each number as it counts down to zero ● If the number is odd, print the current number followed by“OUU!”. ● If the number is even, print the current number followed by “AAA!” ● When it reaches Zero, print “HAPPY NEW YEAR!”
You must create a Java class named TenArrayMethods in a file named TenArrayMethods.java. This class must include all the following described methods. Each of these methods should be public and static.Write a method named getFirst, that takes an Array of int as an argument and returns the value of the first element of the array. NO array lists. Write a method named getLast, that takes an Array of int as an argument and returns the value of the last element...
*q3: Write a public static method named q3 that takes no parameters and has return type void. In this method, you may assume there is a file named "properties.csv" with lines in the format "name, opposed, pure,glad" where "name" is a String and all other values are well-formed integers. There is no header line in this file. This method will create a new * file named "output.csv" in the format "name, pure" containing only these two columns from "properties.csv" and...