answersLogoWhite

0


Best Answer

Like this:

int sum = 0;

for(int i = 1; i<=100; i+=2){

sum+=i;

}

The "for" loop starts the counter i at 1, continues while it is less than or equal to 100, and increments it by 2 at a time.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a loop that sums the odd numbers from 1 to 100 in Java format?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write a program in java to read ten numbers and print sum of ten integers?

Add the numbers into one variable as you read them in. But if you prefer, you can read the numbers into an array and then use a loop to add the numbers together.


Write a c program Fibonacci series using for loop in java?

Exactly what do you mean by 'C program in Java'


What time of loop is used when you know how many times the loop instructions should be processed?

It's best to use a for loop.For example, if you want 10 iterations:for (int i = 1; i


How do you exit in nested loop in java?

You may exit a nested loop in Java using a break with a label for the outer loop.


How do you print non-prime numbers in java?

Loop through some numbers - for example, 2 through 100 - and check each one whether it is a prime number (write a second loop to test whether it is divisible by any number between 2 and the number minus 1). If, in this second loop, you find a factor that is greater than 1 and less than the number, it is not a prime, and you can print it out.


Hoe can you write a programme to claculate 1 plus 2 plus 3..100?

You add the numbers in a loop. Here is an example in Java:int sum = 0;for (int i = 1; i


What are functions in JAVA?

for loop function


Write a for next loop for even numbers beginning at 10 and ending at 50?

int i;for (i=10; i


When is Iteration used in a Java program?

in a loop


How do you write a java program to find the transpose of the matrix for the given elements?

You basically write a nested for loop (one for within another one), to copy the elements of the matrix to a new matrix.


How can you repeatedly execute a code in java script?

1) use for loop 2) do while loop


Which Loop avoids check at every iteration?

All loops available in Java (for, while, do-while) have a loop termination condition that would get executed during every iteration of the loop. Without checking the loop condition the loop cannot be terminated and hence avoiding the loop condition check during iteration is not logic and Java does not do it.