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
A good first step to understanding any kind of text is to :
Vitek1552 [10]

Answer:

find the main idea

Explanation:

6 0
3 years ago
Explain In your own words what a motherboard is and it’s functions?
Arisa [49]

A motherboard is one of the most essential parts of a computer system. It holds together many of the crucial components of a computer, including the central processing unit (CPU), memory and connectors for input and output devices. The base of a motherboard consists of a very firm sheet of non-conductive material, typically some sort of rigid plastic. Thin layers of copper or aluminum foil, referred to as traces, are printed onto this sheet. These traces are very narrow and form the circuits between the various components. In addition to circuits, a motherboard contains a number of sockets and slots to connect the other components.

3 0
3 years ago
Read 2 more answers
Can you make a phone app with angular?.
emmainna [20.7K]

Answer:

yes

Explanation:

4 0
2 years ago
You are given a class named Clock that has one int instance variable called hours.
Vlad [161]

Answer:

public Clock(int hours) {

       this.hours = hours;

   }

Explanation:

In Java programming language, Constructors are special methods that are called to initialize the variables of a class when a new object of the class is created with the new keyword. Consider the complete code for the class below;

<em>public class Clock {</em>

<em>    private int hours;</em>

<em>    public Clock(int hours) {</em>

<em>        this.hours = hours;</em>

<em>    }</em>

<em>}</em>

In this example above,  an object of this class can created with this statement Clock myclock = new Clock(6); This is a call to the constructor and passes a parameter (6) for hours

7 0
3 years ago
Company-wide systems that connect one or more local area networks (LANs) or wide area networks (WANs) are called _____.
fgiga [73]
Web-centric systems
3 0
3 years ago
Other questions:
  • People who work the total hours for which they get paid have
    7·2 answers
  • What type of document would you use the landscape page orientation
    7·1 answer
  • Which is an example of an input device?
    15·2 answers
  • Which of the following dimensions of e-commerce technology involves the integration of video, audio, and text marketing messages
    11·1 answer
  • What defines "print media"? It is media that includes words and text rather than video, such as many blogs. It is media that is
    8·1 answer
  • Liquid-liquid extraction is best suited to separate a mixture of compounds when:
    9·1 answer
  • What is the FaFASA4caster used for
    10·1 answer
  • A popular photo editing application provides customers with the option of accessing a web based version through a monthly subscr
    11·1 answer
  • Will give 5 star and the mark brainleist
    11·2 answers
  • A web application with an SQL server database is found to be compromised by an attacker. On examination, the email IDs of the da
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!