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]
2 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]2 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
Define a void function that calculates the sum (+), difference (-), product (*), quotient (/), and modulus (%) of two integer nu
BabaBlast [244]

Answer:

#include <iostream>

using namespace std;

void multipurpose(int &num1,int &num2,int &add,int &subt,int &multi,int &divi,int &modulo )

{

   add=num1+num2;//adding two numbers...

   subt=abs(num1-num2);//subtracting two numbers...

   multi=num1*num2;//multiplying two numbers...

   divi=num1/num2;//Finding quotient of two numbers...

   modulo=num1%num2;//Finding modulo of two numbers...

}

void print(int add,int sub,int divi,int multi,int modulo) //function to print the values.

{

   cout<<"The addition is "<<add<<endl<<"The subtraction is "<<sub<<endl

   <<"The quotient is "<<divi<<endl<<"The multiplication is "<<multi<<endl

   <<"The modulus is "<<modulo<<endl;

}

int main() {

   int a,b,sum=0,mult=0,divi=0,sub=0,modulo=0;

   cin>>a>>b;

   multipurpose(a,b,sum,sub,mult,divi,modulo);

   print(sum,sub,divi,mult,modulo);

return 0;

}

Enter the numbers

12 12

The addition is 24

The subtraction is 0

The quotient is 1

The multiplication is 144

The modulus is 0

Explanation:

I have created a function multipurpose that has a argument list of two numbers ,and variables for addition,subtraction,multiplication,Division,Modulus and these all are passed by reference.Since the function is of type void so it cannot return anything so the only way to store the result is by passing the variables to store the results by  reference.

The other function print has the arguments of all the results here you can pass them by value or by reference because you only need to print the results.

7 0
3 years ago
How are the functions different and how do i determine the answer
worty [1.4K]

Answer:

this isn't a fair question...

you'll either get 2,3 or 4

not a nice question

3 0
2 years ago
Alguien me prestta una cuenta de osu!, porfa
Mariana [72]

Answer:

english please........

7 0
3 years ago
Access fundamentally refers to the ability of a subject and a(n) ___________ to interact.
mars1129 [50]

Answer:

The correct word for the blank space is: object.

Explanation:

Access Control System (<em>ACS</em>) is a computer structure that allows or restricts users to access to features and information of a server. ACS is used to protect confidential data and to make sure the servers are going to be used by authorized users which diminish malfunctions. One of the basic principles of ACS is letting subjects and objects to interact properly.

5 0
3 years ago
A plan to budget time for studying and activities is referred to as a study routine. study habits. study skills. a study schedul
vesna_86 [32]

Answer:

A study routine

Explanation:

6 0
3 years ago
Read 2 more answers
Other questions:
  • Allan needs to ensure that an object is in a very precise location on a slide. He decides to use the Ruler option to achieve thi
    5·2 answers
  • When a speaker is finished talking, you should allow for _____.
    14·2 answers
  • Try making a character (string) variable and a logical variable . Try creating a variable with a "missing" value NA. You can cal
    11·1 answer
  • Which of the following is true concerning science?
    8·1 answer
  • Cassie is worried about credential management on a network where users often have over six passwords to remember. She’s curren
    13·1 answer
  • You want to add a new Product and Services entry to your client's QuickBooks Online company. The service is installation of a se
    12·1 answer
  • Which statement describing the arcade games played in the 1970s is true?
    14·1 answer
  • Why do people make Among Us games on Ro-blox, and thousands of people play them, when Among Us is free on all devises?
    10·1 answer
  • Describe some common types of charts.​
    13·2 answers
  • Explain how a stored procedure is processed by the DBMS query processor (including the type of return value after the query is p
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!