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
Write a program that asks the user to enter two numbers,obtains the two numbers from the user and prints the sum,product,
Andru [333]

Answer:

#include<iostream>

using namespace std;

//main function

int main(){

   //initialization

   float a1,a2;

//display the message

cout<<"Enter the first number: ";

   cin>>a1;  //store the value

   cout<<"Enter the second number: ";

   cin>>a2;   //store the value

   //display the calculation result

   cout<<"The sum is: "<<a1+a2<<endl;

   cout<<"The Subtraction is: "<<a1-a2<<endl;

   cout<<"The product is: "<<a1*a2<<endl;

   cout<<"The Quotient is: "<<a1/a2<<endl;

}

Explanation:

Create the main function and declare the two variables of float but we can enter the integer as well.

display the message on the screen and then store the input enter by the user into the variable using the cin instruction.

the same process for second input as well, display the message and store the input.

after that, print the output of the calculation. the operator '+' is used to add the two numbers like a1+a2, it adds the number stored in the variable.

similarly, the subtraction operator is '-', product '*' and quotient operator '/'.

and finally, we get the desired output.

4 0
3 years ago
Which of the following are addressed by programing design? Choose all that apply.
Viktor [21]

Answer:

Its B, D, and E

Explanation:

Hope this helps

6 0
3 years ago
Read 2 more answers
What is required to create a game?
Y_Kistochka [10]

Answer: C. competition

Explanation:

6 0
2 years ago
Why were low quality video so often use when Internet connection we’re poorer than they are today
kakasveta [241]
What do you mean? I’m confused with the question, it doesn’t make sense:)
8 0
3 years ago
Anti-malware software should be installed on computer systems to detect and prevent malware infections.
Evgen [1.6K]

Answer:

true

Explanation:

Malware is any software intentionally designed to cause damage to a computer, server, client, or computer network. A wide variety of types of malware exist, including computer viruses, worms, Trojan horses, ransomware, spyware, adware, rogue software, and scareware

Antimalware (anti-malware) is a type of software program designed to prevent, detect and remove malicious software (malware) on IT systems, as well as individual computing devices

6 0
3 years ago
Read 2 more answers
Other questions:
  • What are the advantages and disadvantages of solving a problem that can be broken down into repetitive tasks with recursion as o
    13·1 answer
  • This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given p
    14·1 answer
  • What are the programs required to work in computer
    7·1 answer
  • Whay device is recommended to use to install windows 10
    13·1 answer
  • The base class Pet has private fields petName, and petAge. The derived class Dog extends the Pet class and includes a private fi
    6·1 answer
  • What is eight bits of data called?
    13·1 answer
  • The cost of a postsecondary education increases with the length of time involved in the program.
    10·1 answer
  • Discuss how social media can affect social movements and social change.
    13·2 answers
  • What should you try first if your antivirus software does not detect and remove a virus?
    6·1 answer
  • Derek, a project manager. is involved in an activity that occurs during the system-level requirements analysis. In which activit
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!