Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Testing Strings  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Having a few problems with strings. I am trying to write a program so that I can input two strings, and then test the strings to see whether they are identical or, if not, which comes first in the alphabet.

I have this code and it wont compile.



Any help would be appreciated.
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What error message are you getting?
 
Timothy Willis
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error message:

Cannot resolve symbol - variable string 1
 
author and iconoclast
Sheriff
Posts: 24220
40
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you don't declare string1 anywhere, do you? A declaration include the variables type and name and optionally an initializer. You first use "string1" without having every declared it to be a String.

When you do, I suspect you'll have a problem assigning what "getInt()" returns to a String variable -- maybe there's a getString() method you should use instead?
 
Timothy Willis
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So like this:

public class Strings
{

public static void main (String[] args)
{
String string1, string2;

System.out.print("Please Enter First String: ");
string1 = EasyIn.getString();
System.out.print("Please Enter Second String: ");
string2 = EasyIn.getString();

if (string1.equals(string2))
System.out.println("The Strings are Identical");
else if (string1.compareTo(string2) >0 )
System.out.println("The First String comes first in alphabetical Order");
else if (string1.compareTo(string2) < 0)
System.out.println("The Second String comes first in alphabetical order");

}
}
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is "EasyIn.getString()"?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!