Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: HELP Scope and Parameters in a program

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question HELP Scope and Parameters in a program

    In the following program I need to know 1) the line numbers were variable scope is visible and 2) name the actual and formal parameters in the program.

    1 public class Scope {
    2 public static void test(int num) {
    3 if (num > 10) {
    4 int half = num / 2;
    5 System.out.println(“Half num = “ + half);
    6 } else {
    7 System.out.println(num);
    8 }
    9 }

    10 public static void main(String[] args)
    11 {
    12 int x = 5;
    13 test(x);
    14 }
    15 }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Scope and Parameters in a program

    Please give your answers and explain why you chose them.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Scope and Parameters in a program

    for scope i think lines 4 and 12 and I'm not sure about parameters??

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Scope and Parameters in a program

    I'm confused about:
    the line numbers were variable scope is visible
    I don't see a variable named: scope

    the actual and formal parameters in the program.
    Ask google. That sounds like something from a textbook or that a professor would use.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Scope and Parameters in a program

    The variables used in a program are always declared. The location you declare a variable controls its “visibility” and role in a program. The area where a variable is declared and can be accessed is referred to as its scope"

    What I need to know is were are the variables in my program??

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Scope and Parameters in a program

    where are the variables in my program
    Are you asking about what tokens in your program are variables?
    A variable is given a section of memory that holds a value while the program executes.
    For example, the following statement define a variable to hold an int value:
       int theVar = 123;// define an int variable and give it an initial value of 123

    For an exercise, list the names of the variables in the program you posted.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Scope and Parameters in a program

    Thats why I'm asking cause I don't know where the variables are???

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Scope and Parameters in a program

    Do you know what a variable is and what it is used for?

    For a full and better explanation ask google for a definition of a computer program variable.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Out of scope problem
    By lf2killer in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 21st, 2012, 04:28 AM
  2. Scope problem
    By TP-Oreilly in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 9th, 2011, 08:41 AM
  3. Variable Scope
    By TP-Oreilly in forum Java Theory & Questions
    Replies: 7
    Last Post: October 5th, 2011, 04:08 PM
  4. Scope of Variables
    By PineAppleKing in forum Java Theory & Questions
    Replies: 5
    Last Post: June 11th, 2011, 10:22 AM
  5. The simpler the program - seemingly the more scope for error :p
    By Bacon n' Logic in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 14th, 2010, 06:10 PM