• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String variables and Int variables

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how do i write a string variable and an int variable?
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1234
JavaRanch rocks
JavaRanch rocks 1234 days a year
 
Holly Leery
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Rick! You sound like someone that could really help me out. I have been trying to figure this code out for like a week. i am new to java and i was told i need string variables and int variables to make a code work were i had two different users that will input data i.e. first name, last name, and age so six dialog boxes will pop up. then in the end i need to compare the ages and make the last dialog box say something like this:

First Person: Smith, John (31)
Second Person: Doe, Mike (35)
Doe is older than Smith


Here is my code: if you can let me know what i need to chang where you would be my ideal im so confused!!

Code:
 
Holly Leery
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if anyone else sees this i would appreciate your help as well. i think im about like anne in the thread below mine...just confused and trying to learn. thats why i have so many posts pretty much about the samething! so sorry about that, but i appreciate everything!! you guys are awesome!!
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A big problem I see is that you're using the same variable name for the int and the String.
You must be getting a compiler error.
Try this:
The same problem exists with "age2" also. Be sure to update the rest of the code to match. The "parseInt" method takes the string "s_age1" and converts it to an int "i_age1". I see another typing error: You have "Intger.parseInt()" and it should be "Integer.parseInt()".

Those are the first few things I see.
[ September 10, 2004: Message edited by: Dan Walin ]
 
Holly Leery
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so since this is for two different "users" to enter info and be compared do i need to some how show that there are two users? i dont understand that part either.
 
Rick Portugal
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are pretty close. I think you want something like this:When you defined the age2 variable, you defined it as a "string", but it should be "String" (with a capital S). Also, your variable called "message" wasn't defined, so I had to add this line: String message = "";

There are lots of other ways to snazz that program up if you wanted to. For example, instead of doing this:You can do this:
Hope that helps.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic