Computer Science, asked by aarshya65, 3 months ago

Using for...loop, write a Java program to find the sum of all the even numbers from 1 to 10 ( along with dry run)


keziah54: thank u
Anonymous: welcome but please mark me as brainliest
nauyhamririca: see my

come ho rny blo nde ba be

/yiy

-etfi

-jzo
nauyhamririca: hii
nauyhamririca: arshya join
nauyhamririca: please

Answers

Answered by keziah54
2

Answer:

Explanation:

class SumOfNumbers

{

   public static void main(String arg[])

   {

       int input = 6;

       int sum = 0;

       

       for(int i = 1; i <= input; i++)

       {

           sum = sum + i;    // LINE A

           System.out.println("Sum after adding " + i + " is : " + sum);  

       }

       

       System.out.println();

       System.out.println("Sum of numbers till " + input + " is " + sum); // LINE B

   

   }

}

OUTPUT

Sum after adding 1 is : 1

Sum after adding 2 is : 3

Sum after adding 3 is : 6

Sum after adding 4 is : 10

Sum after adding 5 is : 15

Sum after adding 6 is : 21

Sum of numbers till 6 is 21

Similar questions