Question

Using for loops: - write a Java program that adds numbers between 1 to 100 and...

Using for loops:

- write a Java program that adds numbers between 1 to 100 and prints the result.

- write a Java program that adds odd numbers between 1 to 100 and prints the result

- write a Java program that averages even numbers between 5 to 30 and prints the result

Homework Answers

Answer #1
//TestCode.java
public class TestCode {
    public static void main(String[] args) {
        int sum = 0;
        for(int i = 1;i<=100;i++){
            sum += i;
        }
        System.out.println(sum);
    }
}

////////////////////////////////////////////////////////////////////

//TestCode.java
public class TestCode {
    public static void main(String[] args) {
        int sum = 0;
        for(int i = 1;i<=100;i+=2){
            sum += i;
        }
        System.out.println(sum);
    }
}

////////////////////////////////////////////////////////////////////

//TestCode.java
public class TestCode {
    public static void main(String[] args) {
        int sum = 0, count = 0;
        for(int i = 6;i<=30;i+=2){
            sum += i;
            count += 1;
        }
        System.out.println((1.0*sum)/count);
    }
}
Know the answer?
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
Similar Questions
1- Write a program to print only the even numbers from 100 to 200 2- Write...
1- Write a program to print only the even numbers from 100 to 200 2- Write a program to print the odd numbers from 22 – 99 3- Write a program to calculate howe many even number from 10 to 120 1- Write a program to find only the even numbers for 12 different numbers 2- Write a program to find the odd numbers for 10 different numbers 3- Write a program to calculate howe many even number and how...
write a java code. Write a program using loops to compute the sum of the 30...
write a java code. Write a program using loops to compute the sum of the 30 terms of the series below. 91/(3 + 2 + 2) + 92/(4 - 4 + 5) + 93/(5 + 6 - 8) + 94/(6 - 8 + 11) + 95/(7 + 10 + 14) + 96/(8 - 12 - 17) + . . . . Output: Term Ratio Sum 1 13 13 2 18.4 31.4 etc etc
- Write a python program which prints all the numbers between 1 and 100 that are...
- Write a python program which prints all the numbers between 1 and 100 that are divisible by 3.
IN JAVA Write a program that, given an integer, inserts a '*' between adjacent digits that...
IN JAVA Write a program that, given an integer, inserts a '*' between adjacent digits that are both even and a '-' between adjacent digits that are both odd. Zero should not be considered even or odd. EX: 12467930 Expected Output 12*4*67-9-30
Write a Java program that gets a 4x4 array of numbers and that calculates the sum...
Write a Java program that gets a 4x4 array of numbers and that calculates the sum and average of numbers on the main diagonal, ie the diagonal that goes from the left corner down to the right corner. Examples of resulting programs are: Enter a 4x4 matrix row by row: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 The sum of numbers in the diagonal is: 16 The average of numbers in...
Write a program with while loop that prints all numbers between 5 and 100 (inclusive) that...
Write a program with while loop that prints all numbers between 5 and 100 (inclusive) that are divisible by 5.
Write a program that adds the sum of digits in an integer and loops until 0...
Write a program that adds the sum of digits in an integer and loops until 0 is entered to end the program C++.
Write a program to calculate the sum of all prime numbers between 100 and 200, including....
Write a program to calculate the sum of all prime numbers between 100 and 200, including. A prime number is a natural number greater than 1 and can only be divided by 1 and itself. For example, 5 is a prime number because 5 can only be divided by 1 and 5. we are currently using cin/cout, for /while loops
Write a program that takes n integer numbers from the user, and then counts the number...
Write a program that takes n integer numbers from the user, and then counts the number of even numbers and odd numbers and print them to the screen. Sample Output: Enter how many numbers you have: 10 Enter the 10 numbers: 1 3 19 50 4 10 75 20 68 100 The number of even numbers is: 6 The number of odd numbers is: 4 (( in java ))
write a program that prints all palindromic numbers between 0-9999 into the screen. Note :The code...
write a program that prints all palindromic numbers between 0-9999 into the screen. Note :The code should be written in java language.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT