Results 1 to 3 of 3
  1. #1
    madad2005 is offline Member
    Join Date
    Jul 2007
    Posts
    2
    Rep Power
    0

    Default building file and variable names from variables

    Hi,

    I'm fairly new to java, but need some help with converting what is an easy action in scripting languages but usually not so easy in programming languages. In scripting I would do the following (in pseudo-codish):

    for i=0 , i<10 , i++
    print "hello world no. $i"
    open "filename$i"
    readin "filename$i"
    var.$i = var.$i + var.$(i-1)
    done

    Note the use of the $i. How can I do this in Java? I can do it in C and Fortran, but can't seem to find a reference on how to do it in Java. (The specific commands I used above are an example only)

    Thanks for your help.

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    As far as i see, you are interested in concatenating a string with an integer. Lets assume that you have a string variable str and an int variable i. You will need to create an Integer object from your int primitive value and concatanete as follows:

    Java Code:
    String combined = str + (new Integer(i).toString());

  3. #3
    madad2005 is offline Member
    Join Date
    Jul 2007
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Replies: 4
    Last Post: 07-05-2008, 05:47 AM
  2. Adding file names(Help!!)
    By Gambit17 in forum New To Java
    Replies: 4
    Last Post: 11-09-2007, 07:26 AM
  3. variable access from another file
    By riadmazloum in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 07:13 PM
  4. how can I get the names of variables in runtime?
    By tommy in forum New To Java
    Replies: 1
    Last Post: 07-27-2007, 10:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •