Question

Write Java code segment which prints “YES” when the names contained in two String variables name1...

Write Java code segment which prints “YES” when the names contained in two String variables name1 and name2 are the same, and “NO” if they are different.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

package lecture;
import java.util.*;
public class Stringequal {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Scanner sc=new Scanner(System.in);
       System.out.println("enter first name ");
       String name1=sc.nextLine();
       System.out.println("enter second name");
       String name2=sc.nextLine();
       if(name1.equals(name2))
           System.out.println("yes");
       else
           System.out.println("no");

   }

}

DON'T FORGET TO LIKE.

THANKS BY HEART.

Add a comment
Know the answer?
Add Answer to:
Write Java code segment which prints “YES” when the names contained in two String variables name1...
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
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