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
makkiz [27]
3 years ago
7

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

ine whether such a variable is visible after the body of the for statement
Computers and Technology
1 answer:
xxMikexx [17]3 years ago
6 0

Answer:

  1. public class Main {
  2.    public static void main (String [] args) {
  3.        for(int i = 1; i < 10; i++){
  4.            int num = 0;
  5.            num += i;
  6.        }  
  7.        System.out.println(num);
  8.    }
  9. }

Explanation:

In programming each variable has its scope. For example, a variable defined within the for loop has no longer exist outside the loop body. To illustrate this we can write a short program as presented above.

Firstly, create a for loop that traverse the number 1 - 10 (Line 5 - 8). Within the loop create a variable num and initialize it with zero (Line 6) and increment it with i value for each iteration (Line 7).

Outside the loop, we try to print the num (Line 9). When we run the program this will result in an error as the num which is declared inside the for loop will no longer exist outside the loop body.  

You might be interested in
Which term is defined by the total operating current of a circuit?
Mamont248 [21]

Answer:

OK PERO NOSE LM SOTTY BROTHER

Explanation:

6 0
3 years ago
An organization has a website with a guest book feature, where visitors to the web site can input their names and comments about
kozerog [31]

Answer:

B

Explanation:

6 0
3 years ago
Read 2 more answers
Read the following Selection Sort function and determine the correct answer for blank #2.
lakkis [162]

Answer:

Option(a) is the correct answer to the given fill in the blank of #2

Explanation:

The values[indexOfMin] returns the minimum element in the particular array As in the given question we have to implement the selection sorting .In the selection sorting we have choose the element and compare them others minimum index that's why we have choose the values[indexOfMin] function.

  • The index of min is not the correct function So we have not used in the given fill in the blanks that's why option(b) is incorrect .
  • The  values[startIndex] represent the starting index only that is not suitable for the given question that's why it is incorrect option.

4 0
4 years ago
Samm1E49 ok my username is mosarider489 also if others want to join u can friend me
mixer [17]

Answer:

ok

Explanation:

3 0
3 years ago
Read 2 more answers
A type of sensor used to detect which way around a device is being held. ​
Marta_Voda [28]
There’s 3 main ones accelerometer, gyroscope, and magnetometer.
8 0
3 years ago
Other questions:
  • Coloumn1; Criteria1: Average of best three marks (CA); CA&gt;=40
    13·1 answer
  • Write a program that computes and displays a 15 percent tip when the
    9·1 answer
  • You are building a gaming computer and you want to install a dedicated graphics card that has a fast GPU and 1GB of memory onboa
    6·1 answer
  • To check spelling errors in a document, the Word application uses the _____ to determine appropriate spelling.
    7·2 answers
  • Create a Produceclass that hasan instance variable of type Stringfor the name, appropriate constructors, appropriate accessor an
    13·1 answer
  • Joe runs a handyman service. He enjoys writing and keeping up on the latest trends. He wants to share this information with his
    14·1 answer
  • Who is the intended audience of a pseudocode document?
    14·1 answer
  • I
    6·1 answer
  • How to create create a database in mysql using clv files
    11·1 answer
  • If you're connected to a switch and your NIC is in promiscuous mode, what traffic would you be able to capture
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!