Question about variable names

k, so I have a for() loop that I want to take the value of String fs1 through String fs21 and add them in that order to a String fs. So, my question is, can you do this in a loop? you can do it in PHP, and that's what I'm accustom to.
this is kinda what I want to make
String fs = "";
String fs1 = "foo";
String fs21 = "bar";
for(int i = 0; i<22;i++)
     fs+= (the variable "fs" plus the number of "i", so like fs1, fs2, fs3. . . fs21);
System.out.println(fs);

I think you want to use and array and be careful about using += that way.
StringBuffer buffer = new StringBuffer();
String[] fs = new String[2];
String fs[0] = "foo";
String fs[1] = "bar";
for(int i = 0; i<22;i++)
     buffer.append(fs);
return buffer.toString();

Similar Messages

  • Question about domain name and .mac

    my wife and i are going to move to London and we want a website to update people. now it would be a lot easier to say, "oh, just go to www.domainx.com". (with domainx being whatever domain we buy) rather than saying, "oh go to mac.homepage.iweb.ilife.joseph.page1.com" or whatever massive name they choose. now i would like to publish to .mac because of what they allow you to do. is there anyway i could buy domainx.com and when they go to domainx.com it will send them to my .mac published site. i hope you understand the question. i don't want to be limited by domainx.com but i want the luxury of that short domain name. any help would be amazing. thanks so much!
    ~joseph

    1. Search this forum. It's discussed every minute. The topic is also above yours. Please have a look.
    [Publishing to .mac - how many domains can i have?|http://discussions.apple.com/thread.jspa?threadID=1487530&tstart=0]
    2. iWeb publishes to web.mac.com/yourdotMacId.
    So there really is not much to remember.
    3. Go to the dotMac Help. It's explained there.
    1. [Setting up .Mac to use a personal domain name|http://help.apple.com/mac2/1/help/member/pgs/gen367.html]
    You can set up your .Mac account to use a personal domain name by registering the...
    2. [About .Mac and personal domain names|http://help.apple.com/mac2/1/help/member/pgs/gen366.html]
    Learn how you can use your own personal domain name for your iWeb '08 websites....
    3. [If you're having trouble setting up your personal domain name on .Mac|http://help.apple.com/mac2/1/help/member/pgs/gen369.html]
    Make sure you've registered your domain with an accredited domain name registrar and linked the domain...

  • Question about variable declaration

    Hi all,
    I have a (in fact, two) question(s) about the declaration of variables inside of time-critical code, like render loops or similars.
    Does it really matter to use
    for (int k=0; k<1000; k++)
         for (int l=0; l<1000; l++)instead of
    int k;
    int l;
    for (k=0; k<1000; k++)
         for (l=0; l<1000; l++)concerning the speed of the app? What about doing this with non-basic types -> Objects, like to say Strings ?
    And are there any resources where I can find out more about that and other things like that ?
    Uhm, now it became three q's... Sorry to bother you ;-)
    Skippy

    whoo, maybe I got something totally wrong here.
    Does this mean that
    Image blah;
    for (int i=0; i<100; i++) blah = getImage("test"+i+".gif");will clean up a lot, because there are non-referenced Images and Strings?
    Hmm, anyone told me that
    for (int i = 0; i<100; i++)
    String test = "test"+i;
    System.out.println(test);
    }is disastrous code.
    Damn, ever thought to be a good Java programmer, but every day I get new thoughts I cannot solve these days...
    grmph
    Skippy

  • Question about variable scope

    Suppose theres a class that mixes colors.
    It has an constructor and two methods:
    public class ColorMix {
    //This is just an example but I've tried this and colors
    mix and show up correctly.
    public ColorMix() {
    cmColor = MixColors();
    } //e_constr
    private void mixColors() {
    //do something
    Color1 = createColors();
    Color2 = createColors();
    //etc
    private Color createColors() {
    //create some color-values
    //r, g and b ...
    Color anColor = new Color (r, g, b) //finally create color
    return anColor; //and return that color
    public Color cmColor;
    } // e_class_ColorMix
    My question is: Howcome and how the variable
    'anColor' is referred from the createColors-method to
    the mixColors-method?!? I thought that anColor would
    be out of scope, since its created in the createColors
    I've understood it would be erased once createColors
    is done with?!?
    Or did MixColors make it to the 'anColor' before garbage
    collector?
    Thanks,
    Jani

    I think you are mixing up variables and objects. A variable (like "anColor" in your example) is not the same as an object. A variable is just a reference to an object that exists somewhere in memory.
    Objects are eligible for garbage collection if the running program does not hold any reference to the object anymore.
    Your createColors() method creates a new object of type Color and stores a reference to it in the variable anColor. Then it returns the value of the variable (which is the reference to the Color object) to the calling method: mixColors. There you have another variable (Color1) which will hold the reference to the object.
    So the variable anColor goes out of scope at the end of method createColors(), but the program still has a reference to the object, stored in variable Color1.
    The object is still referenced by the program and will therefore not be garbage collected.
    I'd suggest you read the Java Tutorial: http://java.sun.com/docs/books/tutorial/java/index.html
    Jesper

  • Question about having name for 5 Ghz network

    The subject title sounds stupid, but the question is straightforward. Do you tend to give your 5 Ghz network a different, separate network name in your Airport Extreme? In the "Wireless" options you are presented with the choice to give the 5 Ghz network a different name, thereby giving you the option to connect to the 5 or the 2.4. Is there any benefit to this? And if you don't give it a separate name, to which frequency does your computer automatically connect?

    I think most users tend to use the same network name with "5 GHz" added to indicate which band they are using. The idea here is to simply identify the 5 GHz band, so Apple adds the "5 GHz" by default unless you change this yourself.
    The benefit to assigning a separate name to the 5 GHz band is that you can "force" a computer to connect to this band. Surprisingly to many users, this can also be a negative (see information below). Or, if you plan to "extend" your wireless network with an AirPort Express, you can choose to extend either the 5 GHz band or the 2.4 GHz band.
    If you don't assign a separate name to the 5 GHz band, your computer will automatically connect to the signal with the best combination of strength and low noise.
    Because 5 GHz signals are absorbed by walls, ceilings and any other obstructions much more quickly than 2.4 GHz signals, your computer will likely connect to the 5 GHz band when it is the same room as your wireless router or it has close to line-of-sight with the wireless router. Once you are a few rooms away, or down the hall and around the corner, your computer will likely connect to the 2.4 GHz band because these signals "travel" better.

  • A question about variables and where I should put them!

    Hi, I'm fairly new to java. I'm a first year computer scientist and I'm struggling with where I should put my variables.
    So far on the course I've been able to wing it as we have not been doing object orientated programming, it was more like programming in fortran!
    Anyway if you look at the code below, I need the variables 'speed', 'distance', 'time' and 'tottime', to be calculated in my seperate methods, but then called in my main part to be printed out; however I have no idea where I put them to get this to work!
    The program is by no means complete, it's still a work-in-progress, but I need to get this sorted before I continue.
    Thanks in advance
    /////  LogName: gxm07u
    /////  FullName:
    /////  CreationDate: 2007-11-07 09:30:07
    import java.io.*;
    public class travel {
        public static void printMenu()
             System.out.println("Travel Program\n\nn: Enter a journey\ns: Get complete journey stats\nd: Get Distance travelled stats\nq: quit");
        public static void RoadMenu()
             System.out.println("Type the road type:\nType m: Motorway\nType a: A road\nType b: B road\nType u: Urban road");
        public static void enterRoadType()
             char choice;
             choice = UserInput.readChar();
             switch(choice)
                  case 'm': //motorway
                  case 'M':
                       speed = 85;
                  break;
                  case 'a': // a road
                  case 'A':
                       speed = 70;
                  break;
                  case 'b': //b road
                  case 'B':
                       speed = 55;
                  break;
                  case 'u': // Urban road
                  case 'U':                                     
                       speed = 40;
                  break;     
        public static void enterDistance()
             System.out.println("Type the travel distance: ");
             distance = UserInput.readDouble();
        public static void calcTime()
             time = speed/distance; // time in hours
             tottime = tottime + time; //total time in hours         
        public static void main(String[] argv) {
              int speed = 0;
              double distance = 0;
              double time=0, tottime=0;
         } // end of main
    } // end class

    Your calcTime() can't see variables local to other methods you either need to make them global or pass them in as parameters. To make them global:
    public class travel {
         int speed = 0;
         double distance = 0;
         double time=0, tottime=0;
        public static void printMenu()also you're main method should create a instance of the class
        public static void main(String[] argv) {
    new travel();
    }BTW it's convention to make class names begin with a uppercase letter. Also, look at using the equalsIgnoreCase() for your switch statement as it could save you 4 cases.
    Hope this helps

  • Question about variables in TEXTCOLUMNS !!!HELP

    Hi friends,
    can somebody tell me if it is possible to put varaibles in textcolumns(VARCHAR2)
    like 'Das Fondsvolumen des Fonds betrdgt <Fondsvolumen>' (Fondsvolumen ist the variable--> which is a column of another table in the DB)
    into the database which will be evaluated when you query the column with the text????
    Is that possible and if yes how????
    thanxx
    Schobbi

    Schobbi,
    You could use a view for the
    selection part to replace
    your variables with the concrete
    values. Write a function that returns
    those values/the whole string and use
    it in this view, if you like.
    Hope this helps,
    Karsten

  • Applescript question about variables

    I have a command in AppleScript that goes like this
                                  set focus check box "/app/con[0]/ses[0]/wnd[0]/usr/chk[1,12]"
    I would like to make the "12" a variable, and pass a new value by putting it in a loop
    Something like
                                  set focus check box "/app/con[0]/ses[0]/wnd[0]/usr/chk[1,x]"
    Any suggestions to how to pass variable x in a string?
    Thank you for your time

    "/app/con[0]/ses[0]/wnd[0]/usr/chk[1," & x & "]"
    Proof:
    set x to 12
    "/app/con[0]/ses[0]/wnd[0]/usr/chk[1," & x & "]" = "/app/con[0]/ses[0]/wnd[0]/usr/chk[1,12]" --> true
    Message was edited by: Pierre L.

  • Quick question about class name

    I was reading through some java code and i noticed this line on the class name
    public class SimpleList<E> implements List<E>i was just wondering what does <E> refer too? I'd appreciate any links.
    Thanks

    The <E> portion of class definition is in reference to Generics. Take a look at Generics in the Tutorial.

  • Simple question about domain names

    Correct me if I'm wrong please. Is it my understanding that the only way to get your iweb site to read www.domainname.com and not have http://web.mac.com/ in front of it, is to register a domain name through another site like go daddy, etc...?

    Go to this page for information...
    http://alyeska.altervista.org/en/iWeb_Domains.html

  • An sql question about table names

    Is it possible to create a table with a certain name via programmatic manipulation using sql?
    Here is my code, can you please tell me why it's not working, and if there is a way to make it work? I basicaly need to create tables with names corresponding to names in a vector.
    public void files(){
        try {
                FileInputStream file = new FileInputStream("C:\\Documents and Settings\\Adham\\jbproject\\SeniorProject\\id.ser");
                ObjectInputStream input = new ObjectInputStream(file);
                val = (Vector)input.readObject();
                input.close();
          catch (java.io.IOException IOE) {
                 IOE.printStackTrace();
          catch (ClassNotFoundException cnfe) {
                 cnfe.printStackTrace();
      public void createtables()
      {     files();
            String dsn = "jdbc:odbc:etv";
            String dbUser = "Adham";
            String dbPass = "reqss";
            for (int i = 0; i<val.size(); i++){
            String s = val.elementAt(i).toString();
            try {
                Connection con = DriverManager.getConnection(dsn, dbUser, dbPass);
                Statement stmt = con.createStatement();
                String sql = new String("CREATE TABLE "+s + "(Start INTEGER,"+ "End INTEGER,"+ "Channel VARCHAR(255),"+ "Title VARCHAR(255))");
                stmt.executeUpdate(sql);
                stmt.close();
                con.close();
            } catch (Exception e) {
                e.printStackTrace();
                return;
      }your help is greatly appreciated

    It's not that you can't create a table at runtime. You can execute an UPDATE with CREATE TABLE in it.
    I'm saying that the string you're passing in as the table name probably contains a lot more than just the name that you think it does. Print out that string before you execute the SQL and see what it has.
    You're reading a serialized object stream. That has a lot more stuff in it than just the table name. I'm guessing that the SQL engine is seeing all that stuff and having a problem with it.
    This code can create tables:
    import java.sql.Connection;
    import java.sql.DatabaseMetaData;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    import java.sql.Statement;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;
    public class TableCreator
        public static final String DEFAULT_SQL  = "CREATE TABLE TEST(NAME TEXT(80))";
        public static final String DRIVER       = "sun.jdbc.odbc.JdbcOdbcDriver";
        public static final String DATABASE     = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\Edu\\Java\\Forum\\DataConnection.mdb";
        public static final String USERNAME     = "admin";
        public static final String PASSWORD     = "";
        public static void main(String [] args)
            try
                String tableCreationSQL = ((args.length > 0) ? args[0] : DEFAULT_SQL);
                String driver           = ((args.length > 1) ? args[1] : DRIVER);
                String url              = ((args.length > 2) ? args[2] : DATABASE);
                String username         = ((args.length > 3) ? args[3] : USERNAME);
                String password         = ((args.length > 4) ? args[4] : PASSWORD);
                Class.forName(driver);
                Connection connection   = DriverManager.getConnection(url, username, password);
                Statement statement     = connection.createStatement();
                statement.executeUpdate(tableCreationSQL);
                statement.close();
                connection.close();
            catch (ClassNotFoundException e)
                System.err.println("Couldn't load JDBC driver class");
                e.printStackTrace();
            catch (SQLException e)
                System.err.println("SQL state: " + e.getSQLState());
                System.err.println("SQL error: " + e.getErrorCode());
                e.printStackTrace();
            catch (Exception e)
                e.printStackTrace();
    }Compile it and try it with your own database and creation SQL.
    MOD

  • Question about Variables

    This is probably a fairly simple question, but I've never seen any documentation on it so I'm not sure of the answer.
    Let's say I have the following code:
    var myLoader:URLLoader;
    function someFunction(){
         myLoader = new URLLoader();
         myLoader.addEventListener(Event.COMPLETE, onComplete);
         myLoader.load(new URLRequest("something"));
         function onComplete(e:Event):void{
              //Some Code.
    function someOtherFunction(){
         myLoader = new URLLoader();
         myLoader.addEventListener(Event.COMPLETE, onComplete);
         myLoader.load(new URLRequest("somethingElse"));
         function onComplete(e:Event):void{
              //Some Code.
    My question is, would it be possible for these two URLLoaders to interfere with each other, for instance if they were executed at the same time--even though they're confined to different functions? Thanks for the help.

    that code is problematic.  you only have one reference for two (or more) urlloaders.
    if you only need one, use one:
    var myLoader:URLLoader=new URLLoader();
    function someFunction(){
         myLoader.addEventListener(Event.COMPLETE, onComplete);
         myLoader.load(new URLRequest("something"));
         function onComplete(e:Event):void{
              //Some Code.
    function someOtherFunction(){
         myLoader.addEventListener(Event.COMPLETE, onComplete);
         myLoader.load(new URLRequest("somethingElse"));
         function onComplete(e:Event):void{
              //Some Code.
    if you need more than 1, give them different references.

  • 1 simple question about variable

    I want to make a query. when I open this query, I want to use a variable, that when I open it, the weeknumber automatically is filled in. How can i do that?Does SAP deliverd this already?(SAP-exit)How can I make one?Do I have to use customer exit?

    Hi K,
    For achieving this you have to use a Customer Exit Variable with Default Value. Do you want to fill it with the same week every time or is it current week. If it is the same week everytime then default value will help.
    But if you want to use Current Week then you SAP Exit Variable "Current Calander Week - 0CWEEK". This variable denotes the current calendar week in format YYYYWW.
    Hope this helps.
    Bhargava

  • Very easy question about variables

    Can I convert float-variable to String-variable?

    Hi, a very easy way to convert almost anything is
    called "typecasting". It might sound difficult, but
    it isn't.
    You use it like this example
    > String outcome;
    Double input;
    input = 3.54789654587;
    Output = ""+input;
    That's not casting. It's implicit formatting.
    What it does is making an empty string and pasting
    your number behind it. VERY easy! You can do this
    with allmost every type of variables.What it's doing is creating a StringBuffer, appending an empty string to it, then appending the result of calling toString on the Double, which is itself a String. (Though things change a bit in jdk1.5.) It works because StringBuffer.append has versions for each primitive type, and toString exists for all Objects.
    One problem is that it's not efficient -- you're doing a lot of work behind the scenes to do something that can be done much more simply. But the bigger problem is that it's using operators in a roundabout way and with implicit results. So it's sort of a hack. "+" is the append operator for Strings (well it actually comes down to an implicit method call, or several). Putting the double on the right side of that also causes an implicit format. So you're implicitly formatting a value, and then appending it to nothing, to get a result. You're not actually meaning to append, you're meaning to format, but you're using an append operator.
    The more straightforward way to do it is simply to explicitly format it, using the methods already shown on this thread, or using java.text.DecimalFormat.

  • Question about variables inside methods

    I just want to be sure that I'm clear on something.
    I have a method that is called inside a class, the local variables
    get initialized with my initial values.
    When the method exits, those local variables get marked with
    a zero reference count and are available for GC when the garbage
    collector runs.
    Correct?
    Thanks.
    -brad w.

    when the method destroy,local variable destroy too .In the stack,when stack.pop(),the reference to the object still exists , though object has been removed.according to this , memory leak will appear .SO we should do something like this.
    Stack stack=new Stack(1000);
    for(int a=0;a<1000;a++)
    stack.push(new Integer(a));
    for(int a=0;a<1000;a++)
    System.out.println(stack.pop());
    public Object pop(){
    if(size==0)
    throw new EmptyStackException();
    Object object=elements[--size];
    elements[size]=null; //eliminate  the reference out of life
    return object;
    /code]
    affter that ,the garbage collector can do something what he want to do                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

Maybe you are looking for

  • Exception while executing

    Hi Friends, When I run my application  i have got the following Exception while executing it: com.sap.tc.webdynpro.modelimpl.dynamicrfc.WDDynamicRFCExecuteException: Error connecting using JCO.Client: null What might be the problem. Is it that the JC

  • Lacie Ethernet Disk

    Hi I've got a new LAcie Ethernet BIG disk. Im gonna use it to transfer some data from my MacPRO to Laptop via FTP server on it. Im useing a big files (footage=big *avi files), and i've noticed it's very slow when i'm copying files from MAC > Lacie HD

  • AppleCare off of eBay? Anyone have any success with this?

    I am looking into purchasing AppleCare for my 4 month old Macbook Pro. I am a student so I can get it for $249, but I have seen on eBay where it will sometimes go for less than that. Has anyone purchased AppleCare off of eBay before? If so, how was y

  • Error when Combining Files (Acrobat XI & Office 2010)

    I have a user who is getting an error every time she tries to combine files on her computer. Pdfs will combine just fine. Pdf + MS Office file types fail. Combining two MS Office file types fail. A side issue, maybe related, is that the Acrobat tab i

  • Safari 3.0.4 crash on startup

    All was working well; don't know what I did, but I did it big. Now Safari crashes when attempting to start up. Here is the Crash Report. I can see the thread it crashed on, but don't know how to interpret the report. Can anyone help? Thanks! Pam B. D