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

Write a for loop that computes the following sum: 5+10+15+20+...+485+490+495+500. The sum should be placed in a variable sum tha

t has already been declared and initialized to 0. In addition, there is another variable, num that has also been declared. You must not use any other variables.
Computers and Technology
1 answer:
Strike441 [17]3 years ago
6 0

Answer:

public class num9 {

   public static void main(String[] args) {

       int sum =0;

       int num =5;

       for(num =5; num<=500; num+=5){

           System.out.println(num);

           sum +=num;

       }

       System.out.println(sum);

   }

}

Explanation:

  • Declare and initialize the variables sum and num
  • Use a for loop with the condition for(num =5; num<=500; num+=5) Since the loop will increment by 5 and run from 5 to 500
  • Within the loop, add num to sum at each iteration
  • Print all elements on seperate lines
  • Outside the loop, print the final value of sum

Create a for loop

You might be interested in
Write a program with class name Digits that prompts the user to input a positive integer and then outputs the number reversed an
mr Goodwill [35]

Answer:

Written in Python:

inputnum = int(input("User Input: "))

outputnum = 0

total = 0

while(inputnum>0):

     remainder = inputnum % 10

     outputnum = (outputnum * 10) + remainder

     inputnum = inputnum//10

     total = total + remainder

print("Reverse: "+str(outputnum))

print("Total: "+str(total))

Explanation:

This prompts user for input

inputnum = int(input("User Input: "))

This initializes the reverse number to 0

outputnum = 0

This initializes total to 0; i.e. sum of each digit

total = 0

The following iteration gets the reverse of user input

<em>while(inputnum>0): </em>

<em>      remainder = inputnum % 10 </em>

<em>      outputnum = (outputnum * 10) + remainder </em>

<em>      inputnum = inputnum//10 </em>

<em>      This adds each digit of user input</em>

<em>      total = total + remainder </em>

This prints the reversed number

print("Reverse: "+str(outputnum))

This prints the sum of each digit

print("Total: "+str(total))

7 0
3 years ago
When you need to switch on an electrical current at a remote location, would you use a relay or an amplifier?
ahrayia [7]

Answer:

Relay

Explanation:

They both perform similar functions in terms of control of voltage and current but the relay would be better because although it cannot produce a variable output like that of an amplifier, it has the capacity to isolate its input from its output.

7 0
3 years ago
Please help, I can't find the answer but I understand the topic.
gladu [14]

Answer:

x=(2+3)*3;

Explanation:

3 0
3 years ago
Read 2 more answers
Xavier composed an email message using a webmail application. Listed below are the different elements that Xavier used in his em
dusya [7]
E., sentence casing.
3 0
3 years ago
Read 2 more answers
write a pseducode that will ask the user to enter the amount of a purchase. The program should then compute that state and provi
stira [4]

The pseudocode of the program is simply a prototype of the actual program

<h3>How to write the pseudocode?</h3>

The pseudocode that does the requirements in the question is as follows:

  • Start
  • Get Input for amount of purchase
  • Compute the state tax: sales tax = sales tax percentage * amount
  • Compute the provisional sales tax: provisional sales tax = provisional sales tax percentage * amount
  • Print the taxes

Read more about pseudocode at:

brainly.com/question/24735155

#SPJ1

7 0
2 years ago
Other questions:
  • How would a programming language that allows programs to run on any operating system be classified?
    11·1 answer
  • What does a graphic organizer do
    6·1 answer
  • How are engineers are related to technology
    13·1 answer
  • You are configuring IP settings on a new network. For the external interfaces, you decide to obtain registered IP addresses from
    5·1 answer
  • Name three recent advances that are influencing OS design.
    15·1 answer
  • How can you exaggerate the height of a jump in a photograph
    10·1 answer
  • technology might not possess emotional intelligence but it can certainly influence ours. how have technological changes affected
    7·1 answer
  • Which of the following is a programming language that permits Web site designers to run applications on the user's computer?
    15·1 answer
  • Develop a C program that calculates the final score and the average score for a student from his/her (1)class participation, (2)
    9·1 answer
  • Jjhb ft fv tuning Denise l Debbie
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!