Java for loop sum odd integers between 1 and 99

Question

We would like to write Java code to sum the odd integers between 1 and 99 using a for statement.

public class Main 
{
   public static void main(String[] args)
   {//from  www.  ja v  a  2 s  .  com
     int sum = 0; 
     
     
     //your code here
       
     
     System.out.println(sum);
   } 
} 


public class Main 
{
   public static void main(String[] args)
   {
     int sum = 0; 
     for (int count = 1 ; count <= 99 ; count += 2) {
       sum += count;
     }
       
     
     System.out.println(sum);
   } 
} 



PreviousNext

Related