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
"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequen
weqwewe [10]

int main() {

string simon_Pattern;

string user_Pattern;

int userScore;

int i;

user_Score = 0;

simon_Pattern = "RRGBRYYBGY";

user_Pattern = "RRGBBRYBGY";

for (i = 0; i <= simson_pattern.length; i++) {

if (simon_Pattern[i] == user_Pattern[i]) {

user_Score = user_Score + 1;

} else {

break;

}

}

cout << "userScore: " << user_Score << endl;

return 0;

}

Here it uses two string variable to store “simson’s pattern and user’s pattern”. Then a “for loop” is executed till the end of the string. Inside the for loop both the strings are compared character by character and when found the score is added. If not for loop is exited and finally the score is displayed.

5 0
3 years ago
Read 2 more answers
Power delivered to the hitch of tractors is called
maks197457 [2]
The answer you are looking for is drawbar horsepower. Good luck!
4 0
3 years ago
2 Manter o autocontrole nos ajuda a evitar muitos problemas na nossa vida pessoal e no ambiente profissional. Em se tratando de
Umnica [9.8K]

Answer:

english please

Explanation:

8 0
3 years ago
Test unit 8 edhesive answers ​
True [87]
What are the questions
7 0
3 years ago
A pseudo code that asks the user for their forename and their surname , and then outputs both, separated by a space to the user​
Mamont248 [21]

Answer:

Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode is a "text-based" detail (algorithmic) design tool. The rules of Pseudocode are reasonably straightforward. All statements showing "dependency" are to be indented. These include while, do, for, if, switch.

5 0
2 years ago
Other questions:
  • How can i add card reader to pc answers?
    9·1 answer
  • The overall purpose of a food guide is________.
    11·1 answer
  • Explain the third <br> generation
    6·1 answer
  • Utility software is also known as _____​
    11·1 answer
  • The loss of privacy data has implications:
    5·1 answer
  • )In a graph represented by adjacency matrix u can find all the neighbours of a given vertices in ____Operations
    6·1 answer
  • Which of the following browsers was introduced with windows 10?
    10·1 answer
  • If you are running a server , which of the follow operating system would be best suited ?window 10 or macOS
    8·1 answer
  • Question 3
    13·1 answer
  • Edhesive 9.3 code practice
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!