User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 403,389 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,596 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 3937 | Replies: 10
Reply
Join Date: Sep 2004
Posts: 1
Reputation: dncloud is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dncloud dncloud is offline Offline
Newbie Poster

Help Please help me compare strings

  #1  
Sep 27th, 2004
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!!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 10
Reputation: Jason Marceau is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Jason Marceau Jason Marceau is offline Offline
Newbie Poster

Re: Emergency! PLease help!!!

  #2  
Sep 27th, 2004
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")
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,893
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 111
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Emergency! PLease help!!!

  #3  
Sep 27th, 2004
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.
Reply With Quote  
Join Date: Sep 2004
Posts: 84
Reputation: jerbo is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
jerbo jerbo is offline Offline
Junior Poster in Training

Re: Emergency! PLease help!!!

  #4  
Sep 28th, 2004
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.
Reply With Quote  
Join Date: Jul 2004
Location: Pakistan
Posts: 1,673
Reputation: nanosani is an unknown quantity at this point 
Rep Power: 8
Solved Threads: 49
Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: Emergency! PLease help!!!

  #5  
Sep 29th, 2004
I give you a hint:
 
String a;
String b;
if(a.equals(b)){
return true;
}
Reply With Quote  
Join Date: Dec 2003
Location: Nashville, TN
Posts: 2,333
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Rep Power: 11
Solved Threads: 101
Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: Emergency! PLease help!!!

  #6  
Sep 30th, 2004
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.
Alex Cavnar, aka alc6379
Reply With Quote  
Join Date: Aug 2004
Location: North Carolina
Posts: 25
Reputation: Banderson is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
Banderson's Avatar
Banderson Banderson is offline Offline
Light Poster

Re: Please help me compare strings

  #7  
Sep 30th, 2004
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.
Reply With Quote  
Join Date: Jul 2004
Location: Pakistan
Posts: 1,673
Reputation: nanosani is an unknown quantity at this point 
Rep Power: 8
Solved Threads: 49
Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: Please help me compare strings

  #8  
Sep 30th, 2004
thanks Banderson! for the equalsIgnoreCase
Reply With Quote  
Join Date: Nov 2004
Location: Syudad sa SUGBU
Posts: 11
Reputation: Archer is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Archer Archer is offline Offline
Newbie Poster

Re: Please help me compare strings

  #9  
Nov 29th, 2004
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();
}
Reply With Quote  
Join Date: Dec 2003
Location: Nashville, TN
Posts: 2,333
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Rep Power: 11
Solved Threads: 101
Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: Please help me compare strings

  #10  
Nov 29th, 2004
Originally Posted by Archer
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...
Alex Cavnar, aka alc6379
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 9:32 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC