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
atroni [7]
3 years ago
5

Write a program to store numbers from 1 to 100 in an array. Print out all the even numbers from the array. Use the enhanced FOR

loop for printing out the numbers.
Engineering
1 answer:
Leto [7]3 years ago
4 0

Answer:

The java program to print all even numbers from 1 to 100 is given below.

import java.util.*;

public class Program

{

// integer array of size 100

static int[] num = new int[100];

public static void main(String[] args) {

// array initialized using for loop with values from 1 to 100

for(int j=0; j<100; j++)

{

num[j] = j+1;

}

System.out.println("Even numbers from 1 to 100 are ");

// enhanced for loop

for(int n : num)

{

// testing each element of the array

// only even numbers will be displayed

if( (n%2) == 0)

System.out.print(n + " ");

}

}

}

OUTPUT

Even numbers from 1 to 100 are  

2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100

Explanation:

The program works as described.

1. An integer array, num, of size 100 is declared.

2. Inside for loop which executes 100 times, array is initialized with numbers from 1 to 100.

3. An enchanced for loop differs from normal for loop such that it doesn't has initialization and increment or decrement conditions.

4. The syntax for an enchanced for loop is shown below.

for( datatype variable_name : array_name )

{ }

In the above syntax, the datatype of the variable_name should be the same as that of the array_name.

The array used in program is shown below.

for(int n : num)

5. Inside enhanced for loop, if statement is included to test each element of array, num, for even or odd number.

if( (n%2) == 0)

6. If the number is even, it is displayed followed by a space.

System.out.print(n + " ");

7. The method println() differs from print() such that new line is inserted after the message is displayed.

8. This program can also be used to display odd numbers by changing the condition inside if statement.

You might be interested in
Suppose you have two boxes in front of you. One box contains a Thevenin Equivalent (voltage source in series with a resistor) an
fomenos

Answer:

1. Measure the temperature of the boxes and leave them unconnected.

2. Norton reduces his circuit down to a single resistance in parallel with a constant current source. A real-life Norton equivalent circuit would be continuously wasting power (as heat) as the current source dumps energy into the resistor, even when externally unconnected, while a Thevenin equivalent circuit would sit there doing nothing.

3. The Norton equivalent box would get warm and eventually run out of power. The Thevenin equivalent box would stay at ambient temperature.

8 0
4 years ago
A heat pump is used to warm a building in the winter. This system implements an ideal vapor-compression cycle with R-134a as the
Marrrta [24]

Answer:

See attachment for detailed answer.

Explanation:

Download pdf
5 0
3 years ago
In the dataset "RestRating", the 30 randomly selected patrons give the overall dining experience ratings (Outstanding, Very good
rusak2 [61]

Answer: incomplete question

Explanation:

6 0
3 years ago
Read 2 more answers
A model of living systems as whole entities which maintain themselves through continuous input and output from the environment,
3241004551 [841]

A model of living systems as whole entities which maintain themselves through continuous input and output from the environment, developed by ludwig von bertalanffy is known as Systems theory.

<h3>what are the application of systems theory?</h3>

It is a theoretical framework to understand the working mechanism of an organization.

It is an entity where all the elements necessary to carry out its functions.

A computer is the best  example of showing the mechanism of system theory.

computer is a system which has many smaller sub-systems that have to work in coordinated manner.

These sub-systems are the processor, RAM, motherboard, hard drive and power supply.

Learn more about systems theory , here:

brainly.com/question/28278157

#SPJ4

7 0
2 years ago
What is the difference between science and engineering?
jek_recluse [69]

Answer:

The following table is among some of the discrepancies between some of the different topics.

Explanation:

  • Science seems to be the application of structured organized facts which could be interpreted scientifically because when engineering would be a branch of science which deals with either the profession of acquiring including using technological, computational, economical and severity of adverse effects to design and manufacture equipment and devices that seem to be beneficial to mankind.
  • Science would be a set of information and established frameworks whereas the use of these models and information to construct structures as well as mechanisms becomes engineering.
4 0
3 years ago
Other questions:
  • The atmosphere within a room is at 70 °F dry-bulb temperature, 50 percent degree of saturation, and 14.696 psia pressure. The in
    14·1 answer
  • At a 4 percent annual growth rate in GDP per capita, it will take
    15·1 answer
  • A wastewater treatment plant discharges 1.0 m3/s of effluent having an ultimate BOD of 40.0 mg/ L into a stream flowingat 10.0 m
    11·1 answer
  • Viscous effects are negligible outside of the hydrodynamic boundary layer. (3 points) a. True b. False
    5·1 answer
  • Use the overall heat-transfer resistance presented by the external air and the glass itself to determine the heat flux in W/m2 i
    10·1 answer
  • This is a multi-part question. Once an answer is submitted, you will be unable to return to this part As steam is slowly injecte
    15·1 answer
  • A football player attempts a 30‐yd field goal. If he is able to impart a velocity u of 100 ft/sec to the ball, compute the minim
    6·1 answer
  • In a movie theater in winter, 510 people, each generation sensible heat at a rate of 80 W, are watching a movie. The heat losses
    11·1 answer
  • Guyss I seriously and urgently need help what are the steps to build a headgear ??​
    5·2 answers
  • Which of the following is true about modern hydraulic lifts?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!