Results 1 to 6 of 6
  1. #1
    IYIaster is offline Member
    Join Date
    Jul 2009
    Posts
    46
    Rep Power
    0

    Default Using if statements to determine integers.

    I'm trying to figure out how to make my ints come available depending on something else.
    like

    Java Code:
            if (currentDisplayNum == 1) {
                int RAMsize1 = 3900;
                int RAMsize2 = 1900;
                double CPUinfo1 = 2.4;
                double CPUinfo2 = 1.8;
    
    }else if (currentDisplayNum == 2) {
                int RAMsize1 = 1900;
                int RAMsize2 = 900;
                double CPUinfo1 = 1.4;
                double CPUinfo2 = 0.8;
    ]
    
    This doesn't work.

  2. #2
    webbusiness23 is offline Member
    Join Date
    Jul 2009
    Posts
    8
    Rep Power
    0

    Default

    I'm not sure i understand your question.

    But did you try to declare your variables before the if statement?

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Yep, webbusiness23 has given you the correct answer. Declare your RAMsize1, RAMsize2, CPUinfo1, CPUinfo2 variables before the if block so that they will be visible inside the if/else blocks and also still visible after the if/else blocks have completed.

  4. #4
    pushdown is offline Member
    Join Date
    Jul 2009
    Posts
    6
    Rep Power
    0

    Default

    More general information you check out the topic scope of variables,
    every programming language has own scope implementation and there are various type of scope and binding. In java every code block, in other words matching curly braces defines a scope and all the definition maded in this scope are valid in this scope. i hope i can be helpful

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    AR on user arkins for off topic spam.

    db

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    He has been warned before and now will be banned for 1 week.

Similar Threads

  1. How to determine CPU usage using Java?????
    By JavaEmpires in forum New To Java
    Replies: 5
    Last Post: 03-16-2011, 04:49 AM
  2. Replies: 2
    Last Post: 03-01-2011, 01:30 AM
  3. determine the type of card hand
    By javaman2 in forum New To Java
    Replies: 7
    Last Post: 01-04-2009, 05:11 PM
  4. how to determine the primary key
    By osval in forum JDBC
    Replies: 1
    Last Post: 08-07-2007, 02:31 AM
  5. Replies: 1
    Last Post: 05-20-2007, 11:19 AM

Posting Permissions

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