Welcome to Westonci.ca, the Q&A platform where your questions are met with detailed answers from experienced experts. Connect with a community of experts ready to help you find solutions to your questions quickly and accurately. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately.
Sagot :
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
Thank you for your visit. We're committed to providing you with the best information available. Return anytime for more. We hope this was helpful. Please come back whenever you need more information or answers to your queries. Find reliable answers at Westonci.ca. Visit us again for the latest updates and expert advice.