Answer :
Answer:
The methods are as follows:
public static int countOfLongest(String [] myarray){
int strlen = 0, kount = 0;
for(int i = 0; i<myarray.length;i++){
if(myarray[i].length() > strlen){
strlen = myarray[i].length(); } }
for(int i = 0; i<myarray.length;i++){
if(myarray[i].length() == strlen){
kount++; } }
return kount; }
public static int countOfLongest(int [] myarray){
int diglen = 0, kount = 0;
for(int i = 0; i<myarray.length;i++){
int lengt = String.valueOf(myarray[i]).length();
if(lengt > diglen){
diglen = lengt; } }
for(int i = 0; i<myarray.length;i++){
int lengt = String.valueOf(myarray[i]).length();
if(lengt == diglen){
kount++; } }
return kount; }
Explanation:
This defines the countOfLongest of the string array
public static int countOfLongest(String [] myarray){
This initializes the length of each string and the kount of strings with that length to 0
int strlen = 0, kount = 0;
This iterates through the array
for(int i = 0; i<myarray.length;i++){
The following if condition determines the longest string
if(myarray[i].length() > strlen){
strlen = myarray[i].length(); } }
This iterates through the array, again
for(int i = 0; i<myarray.length;i++){
The following if condition checks for the count of strings with the longest length
if(myarray[i].length() == strlen){
kount++; } }
This returns the calculated kount
return kount; }
This defines the countOfLongest of the string array
public static int countOfLongest(int [] myarray){
This initializes the length of each integer and the kount of integer with that length to 0
int diglen = 0, kount = 0;
This iterates through the array
for(int i = 0; i<myarray.length;i++){
The calculates the length of each integer
int lengt = String.valueOf(myarray[i]).length();
The following if condition determines the longest integer
if(lengt > diglen){
diglen = lengt; } }
This iterates through the array, again
for(int i = 0; i<myarray.length;i++){
The calculates the length of each integer
int lengt = String.valueOf(myarray[i]).length();
The following if condition checks for the count of integer with the longest length
if(lengt == diglen){
kount++; } }
This returns the calculated kount
return kount; }
See attachment for complete program which includes main