• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

String Manipulation...cont!  RSS feed

 
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....
 
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!