1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
wariber [46]
3 years ago
7

2-Write test programs in java to determine the scope of a variable declared in a for statement. Specifically, the code must dete

rmine whether such a variable is visible after the body of the for statement

Computers and Technology
1 answer:
ankoles [38]3 years ago
7 0

Answer:

See Explaination

Explanation:

public class testscope

{

//start of main function

public static void main(String[] args)

{

//varible declration

int i;

int x;

//loop for 10 times

for(i=0; i<10; i++)

{

//initialize value of x to 10

x = 10;

}

//the scope of variable x is visible outside of for loop

System.out.println("The value of x is: "+x);

}

}

See attachment for sample output

nb:

You can clearly see in the output of Java program the value of x is not printed and program return errors. It means the variable x declared inside for loop does not has scope outside the for loop.

You might be interested in
When assigning a value to a string, which of the following rules needs to be followed?
Alecsey [184]

Answer:

Let's say you need to remember some information, the way moviegoers tried to remember the name of the movie. Instead of storing it in your human memory, you can store information in your computer's memory using Python. This is called assigning a string value to a variable.

To assign a string value to a variable in Python, follow this example. Select each part of the code to see how it works with the movie title example.

movieTitle = "Live. Die. Repeat."

This line of Python code is an example of an assignment statement. In an assignment statement, you tell Python, "This variable is assigned this string value."

Explanation:

4 0
3 years ago
All of the following items could be too expensive for someone with only a high school degree to afford except
Papessa [141]
This sounds like a multiple choice answer can I have 4 choices to pick?
7 0
3 years ago
How should students approach the decision to take the SAT or the ACT?
Vikentia [17]

Answer:

I believe that the only way to really make an informed decision as to which test is a better fit for you is to take a full-length diagnostic exam for both the ACT and the SAT before doing any prep. I also would look at the pros and cons for each test.

I personally took the ACT because there is <em>NO PENALTY </em>for guessing on the test. An educated guess won't hurt your score on the ACT.

6 0
3 years ago
Please fill these out. I really need this done.
tatyana61 [14]

Answer:

i can't see this

Explanation:

5 0
3 years ago
Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integer
oksano4ka [1.4K]

Answer:

The program in Python is as follows:

def get_user_values():

   user_values = []

   n = int(input())

   for i in range(n+1):

       inp = int(input())

       user_values.append(inp)

   output_ints_less_than_or_equal_to_threshold(user_values,user_values[n])

def output_ints_less_than_or_equal_to_threshold(user_values, upper_threshold):

   for i in user_values:

       if i <= upper_threshold:

           print(i,end=" ")

           

get_user_values()

Explanation:

This defins the get_user_values() method; it receives no parameter

def get_user_values():

This initializes user_values list

   user_values = []

This gets the number of inputs

   n = int(input())

This loop is repeated n+1 times to get all inputs and the upper threshold

<em>    for i in range(n+1):</em>

<em>        inp = int(input())</em>

<em>        user_values.append(inp)</em>

This passes the list and the upper threshold to the output..... list  output_ints_less_than_or_equal_to_threshold(user_values,user_values[n])

This defines the output.... list

def output_ints_less_than_or_equal_to_threshold(user_values, upper_threshold):

This iterates through the list

   for i in user_values:

If current element is less or equal to the upper threshold, the element is printed

<em>        if i <= upper_threshold:</em>

<em>            print(i,end=" ")</em>

The main method begins here where the get_user_values() method is called

get_user_values()

7 0
3 years ago
Other questions:
  • The ________ is(are) used to display information on the computer's screen.
    13·1 answer
  • Bitnet, one of the predecessors of the internet was launched in 1981. what does bitnet stand for?
    12·1 answer
  • Markaplier nand jackceptieye are the best YT ever who agrees
    5·2 answers
  • Can you install Ubuntu on a hard drive by porting from the folder to the HDD?
    10·1 answer
  • Do u have all the subjects​
    12·2 answers
  • Write a method named removeRange that accepts an ArrayList of integers and two integer values min and max as parameters and remo
    10·1 answer
  • What is abbreviation of the computer​
    15·2 answers
  • The first version of Windows to have a Start button and taskbar was?
    5·1 answer
  • Write a pseudocode to calculate the volume of a cylinder​
    12·1 answer
  • Which of the following is considered true regarding modern work environments?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!