Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

String Manipulation...cont!  RSS feed

 
Jim Hooper
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mmmm...think I'm missing something here...my code is as follows

public static void main(String[] args)
{
String numword = args[0];
String output;
int i;
int i1;
int i2;

if (numword.charAt(0) = "1")
{.......

but will not accept numword.charAt(0). Error -
Java_4a.java:29: unexpected type
required: variable
found : value
if (numword.charAt(0) = "1")
^

Any help greatly appreciated!
Thanks again....
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jim Hooper:

if (numword.charAt(0) = "1")
{.......


should be

if (numword.charAt(0) == '1')

notice the double == and the single quotes.


Personally I would add some checks to ensure that there is a string passed in and that it has a lenght of at least 1. Just good a good habit to be in.
 
Jim Hooper
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou again Steven! )
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!