Question

Q2. Using the table given below, determine the return value of each of the following: (K/U 8 marks) s1.compare To(s2) For dis
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please upvote if you are able to understand this and if there is ant query do mention it in the comment section.

a). CODE:
public class Main
{
   public static void main(String[] args) {
       System.out.println("happy".compareTo("HAPPY"));
   }
}

9 public class Main 10- { 11 - public static void main(String[] args) { 12 System.out.println(happy.compareTo(HAPPY)); 13OUTPUT:

32 ..Program finished with exit code 0 Press ENTER to exit console.)

b). CODE:

public class Main
{
   public static void main(String[] args) {
       System.out.println("123abc".compareTo("abc123"));
   }
}

9 public class Main 10 { 11 public static void main(String[] args) { System.out.println(123abc.compareTo(abc123)); 13 14OUTPUT:

-48 ... Program finished with exit code 0 Press ENTER to exit console.

c). CODE:

public class Main
{
   public static void main(String[] args) {
       System.out.println("hello, world".compareTo("hello, " + "world"));
   }
}

9 public class Main 10 { 11 public static void main(String[] args) { 12 System.out.println(hello, world.compareTo(hello, 1OUTPUT:

0 ... Program finished with exit code 0 Press ENTER to exit console.)

d). CODE:

public class Main
{
   public static void main(String[] args) {
       System.out.println("".compareTo(" "));
   }
}

9 public class Main 10 - { 11 public static void main(String[] args) { 12 System.out.println(.compareTo( )); 13 } 14 } 15OUTPUT:

-1 ... Program finished with exit code 0 Press ENTER to exit console.

e). CODE:

public class Main
{
   public static void main(String[] args) {
       System.out.println("television".compareTo("TV"));
   }
}

11 9 public class Main 10 { public static void main(String[] args) { 12 System.out.println(television.compareTo(TV)); 13OUTPUT:

-= 3 2 ... Program finished with exit code 0 Press ENTER to exit console.

f). CODE:

9 public class Main 10 - { 11 - public static void main(String[] args) { 12 System.out.println(12.compareTo(k)); 13 } 14OUTPUT:

-1 Program finished with exit code 0 Press ENTER to exit console.

g). CODE:

public class Main
{
   public static void main(String[] args) {
       System.out.println("sweet".compareTo("sweet-tooth"));
   }
}

9 public class Main 10 { 11 public static void main(String[] args) { 12 System.out.println(sweet.compareTo(sweet-tooth));OUTPUT:

-6 ... Program finished with exit code 0 Press ENTER to exit console.

h). CODE:

public class Main
{
   public static void main(String[] args) {
       System.out.println("one".compareTo("eighty"));
   }
}

9 public class Main 10 { 11 - public static void main(String[] args) { 12 System.out.println(one.compareTo(eighty)); } 14

OUTPUT:

10 --.Program finished with exit code 0 Press ENTER to exit console.

If something else is required or it was supposed to be done in any other way then please mention it in the comment section otherwise please upvote.

Add a comment
Know the answer?
Add Answer to:
Q2. Using the table given below, determine the return value of each of the following: (K/U...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a method called printReverse() that takes a string and uses recursion to print the contents...

    Write a method called printReverse() that takes a string and uses recursion to print the contents of the string in reverse order. The string itself should not be reversed; it must be left in its original form. The method has the following header:   void printReverse(String s, int i) where s is a reference to the string, and i is an integer parameter that you may use as you see fit. You do not need to code up this method as...

  • Write the following functions, as defined by the given IPO comments. Remember to include the IPO...

    Write the following functions, as defined by the given IPO comments. Remember to include the IPO comments in your submission. Be sure to test your code -- you can use the examples given for each function, but you should probably test additional examples as well -- and then comment-out or remove your testing code from your submission!. We will be testing your functions using a separate program, and if your own testing code runs when we load your file it...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT