q4: Write a public static method named q4 that takes a String as a parameter and
ID: 3703288 • Letter: Q
Question
q4: Write a public static method named q4 that takes a String as a parameter and returns * an int. The return value is the total number of times "1" and "p" appear in the input * String *Hint: If the second argument of the replace method is th matching characters will be * removed (Replaced with nothing) * See (https://docs.oracle.com/Java se/8/docs/api/java/lang/String .html#method. summary) for a * complete list of methods contained in the String class. You may call any of these methods * in your method kak * q5: Write a public static method named q5 that takes a String as a parameter and returns a *String. The returned String is based on the input String as follows: *If the input String has no characters, return "empty" If the input String has less than 3 characters, return "short * If the input String has 3 or more characters but less than 8, return "medium" If the input String has greater than or equal to 8 characters, return "long" If the input String contains any instances of the letterq', return "found q" regardless * of the length of the inputExplanation / Answer
q5)
public static String q1(String input){
String output="";
if(input.length()==0){
output="empty";
}
else if(input.length()<3){
output="short";
}
else if(input.length()>=3 && input.length()<8){
output="medium";
}
else if(input.length()>=8){
output= "long";
}
if(input.contains("q")||input.contains("Q")){
output= "found q";
}
return output;
}
q1)
public static String q1(String input){
String output="";
if(input.length()==0){
output="empty";
}
else if(input.length()<3){
output="short";
}
else if(input.length()>=3 && input.length()<7){
output="medium";
}
else if(input.length()>=7){
output= "long";
}
if(input.contains("m")||input.contains("M")){
output= "found m";
}
return output;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.