I need help with **Java programming** for these questions Write a method named c
ID: 3771872 • Letter: I
Question
I need help with **Java programming** for these questions
Write a method named compareNames that will determine if two names are the same. The two names will be the input arguments to the method. The method should return whether the names are the same of not. Write a main method that will use the method in previous problem to determine if two names entered at the keyboard are the same. Once the decision has been made the main method must display both names and whether or not the names are the same. You may use either console input/output or JOptionPane input / message dialog output (GUI input / output).Explanation / Answer
import java.util.*;
public class CompareNamesDemo{
static boolean compareNames(String s1,String s2)
{
if(s1.equals(s2))
return true;
else
return false;
}
public static void main(String []args){
Scanner sc=new Scanner(System.in);
String name1,name2;
System.out.println("enter name1");
name1=sc.next();
System.out.println("enter name2");
name2=sc.next();
System.out.println("name1"+name1);
System.out.println("name2:"+name2);
if(compareNames(name1,name2))
System.out.println("names are equal");
else
System.out.println("names are not equal");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.