Question

Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the...

  1. Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the Maximum of the 2 values
  2. Write a public static method named getMinOf2Ints that takes in 2 int arguments and returns the Minimum of the 2 values
  3. Write apublic static method named getMaxOf3Ints that takes in 3 int arguments and returns the Maximum of the 3 values
  4. Write a public static method named getMedianOf3Ints that takes in 3 int arguments and returns the Median Value of the 3 values
  5. Write a public static method named printMinOf3Ints that takes in 3 int arguments of type int and prints the minimum value of those 3 ints Example: “The min is “ + minVal
  6. Write a public static method named getProdOfAllPositiveInts that takes in 1 int argument and returns the product of all the values between 1 and that number. If the argument is NON-positive return 0
  7. Write a public static method named getProdOfAllNegativeInts that takes in 1 int argument and returns the product of all the values between -1 and that number. If the argument is NON-negative return 0
  8. Write a public static method named isProdOfAllNegativeIntsNegative that takes in 1 int argument and returns true if the product of all the values between -1 and that number is negative, and false otherwise.
  9. Write a public static method named getCharAtIndex that takes in 2 arguments, a String s, and an int index. The method should return the char found at the index location of the string or if not found return a ‘?’
  10. Write a public static method named getCountOfCharInString that takes in 2 arguments, a String s, and a char c. The method should return an int representing the number of times the char was found within the string.
  11. Write a public static method named getStringReversed that takes in 1 argument of type String and returns the String in reverse order.
  12. Write a public static method named getStringTitleCased that takes in 1 argument of type String and capitalizes the first letter of each word in the String, then returns the title cased string. Example: Input: “the dog ate my homework!” Returns: “The Dog Ate My Homework!”
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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"));  
}
}

Add a comment
Know the answer?
Add Answer to:
Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a static method named middleValue that takes three int arguments, and returns an int. When...

    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...

    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...

    ​​​​​​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...

    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....

    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....

    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...

    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...

    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...

    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...

    *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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT