in Java please
(a) Write a static method abbreviate( ) which is passed a String s and an int max. The method returns a new String which contains the content of s abbreviated to at most max characters, but where the last three characters are ellipses (i.e., the characters . . .).
For example, if s is "Too bad Spongebob’s not here to enjoy Spongebob not being here. ---Squidward." and max is 10, the method returns the 10-character String "Too bad..." If s is shorter than max characters, return the original String. If max is less than 3 and less than the length of s, return the empty String.
(b) Write a main method that calls the abbreviate method twice, and prints the result to the screen each time. The first call should abbreviate the String "How now, brown cow?" down to 10 characters. The second call should abbreviate the result of the first abbreviation down to 5 characters.
public class Main{
public static String abbreviate(String s, int max) {
if (s.length() <= max) {
return s;
}
return s.substring(0, max - 3) + "...";
}
public static void main(String[] args) {
System.out.println(abbreviate("How now, brown cow?", 10));
System.out.println(abbreviate("How now, brown cow?", 5));
}
}

in Java please (a) Write a static method abbreviate( ) which is passed a String s...
programming language is JAVA: We wish to implement a method String insert(char c, String s) that returns a string with c inserted in the correct position in already sorted String s. To do so we will implement insert as follows: static String insert(char c, String s) { return insertHelper(c, "", s); } static String insertHelper(char c, String left, String right) {} // strip leading characters from right, & append to left 'till insertion point found. Now return left + c + right. For...
Write a method called printReverse() that
takes a string and uses recursion to print the contents of the
string in reverse order. The string itself should
not be reversed; it must be left in its
original form.
The method has the following header:
void printReverse(String s, int i)
where s is a reference to the string, and i is an integer
parameter that you may use as you see fit. You do not need
to code up this method as...
java
/* Q2 (10 pts): Write a method called method that accepts an integer parameter * * * * and returns a sum of the first n terms of the sequence. * In other words, the method should generate the following sequence: 1 + 1/2 + 1/3 + 1/4 + ... 1/n * For example, method2(2) will return 1.5 since 1+1/2 = 1.5 * method2 (15) will return 3.3182289932289937 * You may assume that the parameter n is nonnegative. */...
4. Write a static method named ConcatStrings that is passed any number of parameters of type String, and returns a single string that is the concatenation of the strings passed. (4 pts.) 5. Write a static method named ConcatObjects that is passed any number of parameters of type Object, and returns a single string that is the concatenation of the result of the call to toString() for each of the objects. (4 pts.) 6. Write a class named Triplet that...
3. Write a method buildString which takes a 2D array of characters (char), and returns a string that is built from all the characters in that array. For example, the following method call should return "hello!" buildString( new char[] [ 'h', 'e',
(IN JAVA) Write a program named Review.java and implement the following methods: public static boolean isValidTicTacToeBoardString(String str) This method takes as its parameter a String that contains 9 characters representing the status of the Tic Tact Toe game. The String is mixed with X, O, x, o, and other letters. The first three letters represent the first row, letter 4 through letter 6 represent the second row, and the rest for the last row. To be considered as a valid...
Please write this in java
Write one static method to print each character in the
output. There should be methods to print: H, E, L, O,
(comma), W, R, D and (exclamation point). The method
to print H should be called printH() and the method to
print the comma should be called printComma(). Make
sure to separate characters with a new line in the method
(except the comma) as shown on right. Write a method called
printHelloWorld() to call the...
5. Write a static method "f(n)" in the space provide, that returns O if n is even, and if n is odd, returns 1 or -1 according as n is greater than or less than 0. importjava.util.Scanner; public class Q_05 Your "f(n)" method: public static void main(String args[]) mana int n; Scanner input = new Scanner(System.in); System.out.print("Please enetrn: "); n=input.nextInt(); System.out.println(f(n)); "Method f(n)" 7. Write a static method "max" in the space provide, that returns the maximum value from 3...
Q1)(20p)Write a static member function called
removeLongestRepeatingSegment that takes a String argument. The
method will return a new String by removing the logest segment that
contains consequtively repeating characters.
public static void main(String []args){
String s=”1111222223333311111111444455552222”;
String res= removeLongestRepeatingSegment(s); will return
“11112222233333444455552222”
}
public static String removeLongestRepeatingSegment(String
s){
---------------
Q2)15p)Given a list of objects stored (in ascending order) in a
sorted linked list, implement member method which performs search
as efficiently as possible for an object based on a key....
Text message abbreviation decoder (Java) (1) Complete the following method: /** * Decodes the text abbreviation. * * @param textAbbr Text abbreviation. * @return The decoded abbreviation if known. Otherwise, returns Unknown. */ public static String decTextAbbr(String textAbbr) { // FILL IN BODY } If the parameter matches a known text message abbreviation, return the unabbreviated form, else return: Unknown. Support two abbreviations: LOL -- laughing out loud, and IDK -- I don't know. For example: decTextAbbr("LOL") returns laughing out...