How can I write a program that will read as input two strings and display the word true if the strings are the same and false otherwise. In this activity, two strings are the same if they contain exactly the same characters in the same order (i.e. 'A' and 'a' are not the same characters).


Please help!!! And type give me the code for that !
thank you!!

store the input ia a string variable and then use an if statement to see if they are the same:

if ( inputA == inputB)
System.out.println("True");
else
System.out.println("False")

dncloud, we do not support the direct answering of homework questions on these forums without you putting in some effort yourself.

So let's break the problem down.

- Prompt user to enter string one
- Get string one from keyboard
- Prompt user to enter string two
- Get string two from keyboard

- Use Jason's algorithm above to compare if the two strings are equal
- Display the result

Do you know how to do each of those things individually? If so, you can put them all together to build your program.

Actually the above will not work.

You need to look at the .equals and the .toUpper, or .toLower methods for a String.

This should get you going in the right direction.

I give you a hint:

String a;
String b;
if(a.equals(b)){
return true;
}

I slightly modified your post's topic to make it more polite. "Emergency! PLease help!!!" implied that you deserve precedence over someone else's post, which is kind of considered poor etiquette, and could be considered rude, frankly. Additionally, your thread title has no relevance to your actual question. Creating a relevant thread title also helps you attract people who could help with your problem.

Just letting you know for future reference.

Hi dncloud, nanosani has put you on track pretty good. You use equals to compare strings. If you do not care whether or not the case of the two strings are identical you can use the equalsIgnoreCase() method.

thanks Banderson! for the equalsIgnoreCase

uhmmm, guy, how could I declare variables for string in TURBO C? isn't it:

#include<stdio.h>
#include<string.h> /* is this right??? */
int z=0;
char x;
main()
{
     printf("blah blah blah");
     scanf("%s",&x);
     z=strlen(x); /*can I use this???  cause in my pc, it says that posible use of 'x'...
                     I would like to count the number of character the user inputs...*/
     printf("it's %d",z);
     getch();
}

uhmmm, guy, how could I declare variables for string in TURBO C? isn't it:

#include<stdio.h>
#include<string.h> /* is this right??? */
int z=0;
char x;
main()
{
     printf("blah blah blah");
     scanf("%s",&x);
     z=strlen(x); /*can I use this???  cause in my pc, it says that posible use of 'x'...
                     I would like to count the number of character the user inputs...*/
     printf("it's %d",z);
     getch();
}

Just as a passing aside, this is the Java forum...

And don't forget it's extremely rude to hijack other peoples' threads.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.