This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Production-Ready Serverless (Operational Best Practices) and have Yan Cui on-line!
See this thread for details.
Win a copy of Production-Ready Serverless (Operational Best Practices) this week in the Cloud/Virtualization forum!
  • 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
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

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! )
 
I have always wanted to have a neighbor just like you - Fred Rogers. Tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!