In Java, write a method which, given an array of Strings and a char as the parameters, will find the number of Strings which contained that char (in any position). The method will return that number back to the main program
Dear Student ,
As per requirement submitted above kindly find below solution.
Java method :
//java method to count the characters in the strings
public static int countChar(String [] strings,char
c)
{
//declaring variable to store
character counts
int count=0;
//using for loop
for(int
i=0;i<strings.length;i++)
{
//checking
whether string contains character c
if(strings[i].indexOf(c)!=-1)
{
//if character c found in the strings[i]
then
//increment count
count++;
}
}
return count;
}
**********************************
Demonstration :
Here new java class with name "charCount.java" is created which contains below code.
charCount.java :
//Java class
public class charCount {
//main() method
public static void main(String[] args) {
//declaring array to strings
String [] names=new
String[]{"Virat","Rahul","Jim"};
//call method and print number of
number of string contains given character
System.out.println("Number of
strings contains a : "+countChar(names, 'a'));
}
//java method to count the characters in the
strings
public static int countChar(String [] strings,char
c)
{
//declaring variable to store
character counts
int count=0;
//using for loop
for(int
i=0;i<strings.length;i++)
{
//checking
whether string contains character c
if(strings[i].indexOf(c)!=-1)
{
//if character c found in the strings[i]
then
//increment count
count++;
}
}
return count;
}
}
==================================
Output :Compile and Run charCount.java to get the screen as shown below
Screen 1:charCount.java

NOTE :PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.
public class StringCharCounter {
public static int countStringsContainingChar(String[] strings, char character) {
int count = 0;
for (String str : strings) {
if (str.indexOf(character) != -1) {
count++;
}
}
return count;
}
public static void main(String[] args) {
// Example usage
String[] strings = {"Hello", "World", "Java", "Programming"};
char character = 'o';
int count = countStringsContainingChar(strings, character);
System.out.println("Number of strings containing the character '" + character + "': " + count);
}
}
In Java, write a method which, given an array of Strings and a char as the...
JAVA PLEASE!
Write a method called displayPets that takes an array of strings as input. The method should display the contents of the pets array on one line. Each name should be separated by a space. Use an enhanced for loop to iterate the array. Make sure to declare modifier, parameters and return values. Given an array String[] pets = {"Lucky", "Slinger", "Beast", "Trumpet", "Lulu", "Shadow", "Daisy"} A sample run when calling displayPets(pets) from main() would look like: Pets names:...
Java programming: I need to create a method that is given a 2D char array and a String that returns a part of the original 2D array. The input string will tell the method which rows from the input array need to be returned. For example, a 5x5 char array input along with a string "0 4" would return rows 1 and 5 of the input array. The String input will always be numbers divided by spaces and will not...
Write a method named avgLength which takes an array of Strings as an input parameter and returns a double. The method should calculate and return the average length of all the strings in the array (in java langauge)
Write a function that takes an array of C-strings as a parameter and the number of elements currently stored in the array, and returns a single C-string pointer that is the concatenation of all C-strings in the array. Note: The function must take 2 parameters and return "char *". Any other ways will cause some deduction of points.
in java!! Write a method to check prefix of two strings that have more than 3 characters. A 3-char prefix of a word “class” will be “cla”. The method should take two strings as parameters, then compare 3-char prefix of two strings. Write a method to check suffix of two strings that have more than 3 characters. A 3-char suffix of a word “world” will be “rld”. The method should take two strings as parameters, then compare 3-char suffix of...
Write a method will accept an array of Strings. This method should return the string that comes after all the other strings in lexicographical order. (Assume all the Strings only contain lower case letters. In Example: No number, no Capitals and no Symbols) lastString({“hola”, “word”, “night”, “boom”}) → “word” lastString({“java”, “is”, “so”, “much”, “fun”}) → “so” lastString({“i”, “love”, “java”}) → “love” //precondition: words.length >0 public static String lastString(String[] words) { }
In java please write a method List toList(String[] array) that converts its argument array of strings to a list of strings and then returns it.
Write a Java program that will create an array of Strings with 25 elements. Input Strings from the user and store them in the array until either the user enters “quit” or the array is full. HINT: the sentinel value is “quit” all lowercase. “Quit” or “QUIT” should not stop the loop. HINT: you have to use the equals method (not ==) when you are comparing two Strings. After the input is complete, print the Strings that the user entered...
Using java, write a method called findSmallestEven() that receives a 2-dimentional array of integers as a parameter and returns the smallest even number contained within it. [Note: Any hardcoded return value will not be accepted]
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',