Thursday, 1 March 2018

for loop in javaNested for loop Star Pattern, Sum of even and odd number...





package javaapplication5;





public class JavaApplication5 {



   

    public static void main(String[] args)

    {

        int esum=0,osum=0,tsum=0;

       

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

        {

       

            if (i%2==0)

            {

            esum=esum+i;

               

            }

            else if (i%2!=0)

            {

                osum=osum+i;

            }

           

            tsum=tsum+i;

           

           

        }

       

        System.out.println("Sum of even no is "+esum);

        System.out.println("Sum of odd no is "+osum);

        System.out.println("Total from addition "+(esum+osum));

       

        System.out.println("Total from loop "+tsum);

       

       

       

       

       

       

       

       

       

       

       

       

       

    }

   

}



No comments:

Post a Comment

Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...