| Author |
Testing Strings
|
Timothy Willis
Greenhorn
Joined: Nov 13, 2004
Posts: 4
|
|
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.
|
 |
Mike Gershman
Ranch Hand
Joined: Mar 13, 2004
Posts: 1272
|
|
|
What error message are you getting?
|
Mike Gershman
SCJP 1.4, SCWCD in process
|
 |
Timothy Willis
Greenhorn
Joined: Nov 13, 2004
Posts: 4
|
|
Error message: Cannot resolve symbol - variable string 1
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
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?
|
[Jess in Action][AskingGoodQuestions]
|
 |
Timothy Willis
Greenhorn
Joined: Nov 13, 2004
Posts: 4
|
|
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
Joined: Mar 13, 2004
Posts: 1272
|
|
|
What is "EasyIn.getString()"?
|
 |
 |
|
|
subject: Testing Strings
|
|
|