Question

Write a Java program which uses a for loop to sum all the even numbers from...

Write a Java program which uses a for loop to sum all the even numbers from 1 to 30.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
//SumEven30.java
public class SumEven30 {
    public static void main(String args[]){
        int sum = 0;
        for(int i = 2;i<=30;i+=2) {
            sum = sum + i;
        }
        System.out.println("Sum = " + sum);
    }
}

Sum 240 Process finished with exit code 0

\color{red}Please\; upvote\;the \;solution \;if \;it \;helped.\;Thanks!

Add a comment
Know the answer?
Add Answer to:
Write a Java program which uses a for loop to sum all the even numbers from...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a complete Java program that uses a for loop to compute the sum of the...

    Write a complete Java program that uses a for loop to compute the sum of the even numbers and the sum of the odd numbers between 1 and 25.

  • Write a program using the LOOP instruction to sum all the even numbers from 20H to...

    Write a program using the LOOP instruction to sum all the even numbers from 20H to 80H. Write a program using the ADC (or add with carry) instruction to add these two 48 bit numbers. Assume the first number is store at an address starting 400H and that the second number is stored at an address starting at address 500H. Store the results in memory starting at address 600H. (Note that each number consists of three 16 bit words). Show...

  • write the program in VBA b. Write a program that uses a For loop to perform...

    write the program in VBA b. Write a program that uses a For loop to perform the following steps: a. Prompt the user to input two integers: firstNum and secondNum(firstNum must be less than secondNum). b. Output all odd numbers between firstNum and secondNum. c. Output the sum of all odd numbers between firstNum and secondNum. d. Output all even numbers between firstNum and second Num. e. Output the sum of all even numbers between firstNum and secondNum.

  • java in simple way pla help me 1. Write a program that uses a while loop...

    java in simple way pla help me 1. Write a program that uses a while loop to read 10 integer numbers from file "numbers.in" and prints their sum and average on the screen as follows: The sum is n and average is m. Where n and m are the computed sum and average, respectively.

  • In java, write a program that gets 10 integer numbers from the user using user input,...

    In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read.   Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1:  use a while loop. version2:  use a do-while loop. version 3:  use a for loop. For each version, use a loop to input 10 int numbers from the user...

  • (java) Write a While loop that prompts the user for only even numbers. Keep prompting the...

    (java) Write a While loop that prompts the user for only even numbers. Keep prompting the user to enter even numbers until the user enters an odd number. After the loop ends, print the sum of the numbers. Do not include that last odd number. You should not store the numbers in an array, just keep track of the sum. Make sure to use a break statement in your code. You may assume that a java.util.Scanner object named input has...

  • I have to write a program in java which uses while loops. 1.prompt the user to...

    I have to write a program in java which uses while loops. 1.prompt the user to input two intergers: firstnum ans second numnumber. (first number must be smaller that the second number). 2. Output all the even numbers between first number and second number inclusive. 3. Output the sum of all the even number between first number and second number inclusive. 4 Output all the odd numbers between first number and second number inclusive. 5. Output the sum of all...

  • Please write a java program that inputs positive numbers using a while loop until a negative...

    Please write a java program that inputs positive numbers using a while loop until a negative number is input and finds the sum of the numbers input

  • Write a program with loops that compute a.The sum of all even numbers between 2 and...

    Write a program with loops that compute a.The sum of all even numbers between 2 and 100 (inclusive). b.The sum of all squares between 1 and 100 (inclusive). c.All powers of 2 from 20 up to 220. d.The sum of all odd numbers between a and b (inclusive), where a and b are inputs. Note*: For part d, enter 3 and 21 as input Output should be: a. 2550 b. 338350 c. 1.0 2.0 4.0 8.0 ... 1048576.05 d. 120

  • Write a complete java program that prompts the user for their name and two numbers. The...

    Write a complete java program that prompts the user for their name and two numbers. The correct java methods and parameters must be passed to find the length of the name entered and return “TRUE” if the sum of numbers is even, or FALSE if the sum of numbers is odd: Notes included in the program Sample Program Please enter a name and I will tell you the length of the name entered John Then length of the name John...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT