Computer Science, asked by sharanya200636, 9 months ago

void compare(String,String)- to compare the length of the two strings and print the longer of the two.

pls just write that much code.
Its urgent pls help
I will mark you the brainliest​

Answers

Answered by sugeetachauhan498
2

Answer:

learn more about comparing string in java using the equals to (=) operator. in this article, your are going to learn how to compare strings and the program the occur when you compare string using equals to (=) operator.

Introduction_ the string is a special class in java we use string regularly in java program.so comparing two strings is a common practice in java in this articles,I tried to answer the most common questions, about the string, like how do I compare string in java,? comparing string in very helpful during processes like out the tieadion sorting, reference matching etc. i have listed three different way to compare string in java. . 1. ... using equals ()( ) method comparing the conten .2. using== operator comparing the object reference.3. using compartor method ( comparing string texicogra phically.) .

Answered by Unni007
4

strlen returns the number of characters in a C string, excluding the NULL character.

#include <stdio.h>

#include <string.h>

int main( )

{

char str[ ] = "Look Here";

printf("Number of characters in \'%s\' is %d", str, strlen(str));

return 0;

}

If you want to compare first n characters of two strings, then strncmp can be used. Its return value is similar to strcmp

#include <stdio.h>

#include <string.h>

int main( )

{

char str1[ ] = "Look HerE";

char str2[ ] = "Look Here";

printf("%d\n", strncmp(str1, str2, 8));

printf("%d\n", strncmp(str1, str2, 9));

return 0;

}

Example

#include <stdio.h>

#include <string.h>

int main( )

{

char str1[ ] = "Look HerE";

char str2[ ] = "Look Here";

char str3[ ] = "Look Here";

char str4[ ] = "Look Her";

printf("%d\n", strcmp(str1, str2));

printf("%d\n", strcmp(str2, str3));

printf("%d\n", strcmp(str3, str4));

return 0;

}

Similar questions