Computer Science, asked by susama35, 1 year ago

int n = "BUTTER".compareTo("BUT");

Answers

Answered by Anonymous
4

Given :-

int n ="BUTTER" .compareTo("BUT");

Here there are 2 strings compared to each other .

The first string is "BUFFER" .

The second string is "BUT" .

Here we have to note that :-

→ If the first string is bigger than the second , then "n" will be a positive number .

→ If the first string is shorter than the second , then "n" will be a negative number .

→ If they are equal , then the value will be 0 .

Here BUTTER > BUT :

Hence n will be more than 0 .

BUTTER has B,U,T,T,E,R - 6 characters .

BUT has B,U,T - 3 characters .

Hence the difference is 6 - 3 = 3 .

The value of n will be 3 .

Answered by Anonymous
0

\huge\red{Answer }

Given :-

int n ="BUTTER" .compareTo("BUT");

Here there are 2 strings compared to each other .

The first string is "BUFFER" .

The second string is "BUT" .

Here we have to note that :-

→ If the first string is bigger than the second , then "n" will be a positive number .

→ If the first string is shorter than the second , then "n" will be a negative number .

→ If they are equal , then the value will be 0 .

Here BUTTER > BUT :

Hence n will be more than 0 .

BUTTER has B,U,T,T,E,R - 6 characters .

BUT has B,U,T - 3 characters .

Hence the difference is 6 - 3 = 3

HOPE IT HELPS YOU !!

Similar questions