If Your data is age, then You have to compare ints, not Strings..
You do comparision basically in two steps:
First is: Cast from String to int
Second: compare ints
1*
String a = "7";
String b = "8";
int ia = Integer.parseInt(a);
int ib = Integer.parseInt(b);
if ( ia != ib )
System.out.println("numbers are not equal");
a = "8";
b = "8";
ia = Integer.parseInt(a);
ib = Integer.parseInt(b);
if ( ia == ib )
System.out.println("numbers are equal");
or, using if else statement:
2*
String a = "8";
String b = "8";
int ia = Integer.parseInt(a);
int ib = Integer.parseInt(b);
String l = ( ia == ib )?"":" not";
System.out.println("numbers are" + l + " equal");
pacior
If You are comparing text, rather than numbers, You can use equals
method of String class.
On Jul 22, 8:32 pm, ben <[email protected]> wrote:
> hi all,
>
> i want to know how to compare strings...
> for example if i get the age as a string... how can i compare them and
> get the largest value to print...
>
> thanks
>
> ben...
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---