Thursday, 1 March 2018

Do while and Foreach Loop in Java









Do While


package javaapplication7;


public class JavaApplication7 {

   
    public static void main(String[] args)
    {
        int i=10;
        do 
        {
            System.out.println(i);
            i--;
        } while (i>0);
        
       
    }
    
}

Foreach 


package javaapplication8;


public class JavaApplication8 {

    
    public static void main(String[] args) 
    {
        String[] fruits = new String[] { "Orange", "Apple", "Pear", "Strawberry" };

     for (String x : fruits)
     {
         System.out.println(x);
    
     }
    
}
}

While Loop in Java with Factorial Program example







package javaapplication6;





public class JavaApplication6 {



   

    public static void main(String[] args)

    {

      int fac=1;

        int i=25,temp;

        temp=i;

        while(i>=1)

        {

        fac=fac*i;

        i--;   

        }

       

        System.out.println(temp+"!="+fac);

    }

   

}



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);

       

       

       

       

       

       

       

       

       

       

       

       

       

    }

   

}



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);

       

       

       

       

       

       

       

       

       

       

       

       

       

    }

   

}



Tuesday, 27 February 2018

IF - Else Conditional Statement in Java (Check input Number is Even or Odd)









package javaapplication4;



import java.util.Scanner;





public class JavaApplication4 {



   

    public static void main(String[] args)

    {

        Scanner obj=new Scanner(System.in);

        int i;

        System.out.println("Enter the Number: ");

        i=obj.nextInt();

        if (i%2==0)

        {

            System.out.println(i+" is an even number");

        }

        else   

        {

            System.out.println(i+" is an Odd number");

        }

    }

   

}



How to get user input in java programming PART-3







package javaapplication3;



import java.util.Scanner;









public class JavaApplication3

{



 

    public static void main(String[] args)

    {

       byte b=127;

    System.out.println("value of byte variable is "+b);

    short s=32767;

    System.out.println("value of short variable is "+s);

    long l=659685085;

    System.out.println("value of long variable is "+l);

    int i=654654;

    System.out.println("value of int variable is "+i);

    float f=5.323232f;

    System.out.println("value of float variable is "+f);

    double d=543545435.43;

    System.out.println("value of double variable is "+d);

    char c='a';

    System.out.println("value of char variable is "+c);

    boolean bo=true;

    System.out.println("value of boolean variable is "+bo);

   

        System.out.println("------------------------------------------------");

     

        Scanner obj=new Scanner(System.in);

        b=obj.nextByte();

    System.out.println("value of byte variable is "+b);

 

        s=obj.nextShort();

            System.out.println("value of short variable is "+s);

        l=obj.nextLong();

          System.out.println("value of long variable is "+l);

        i=obj.nextInt();

            System.out.println("value of int variable is "+i);

        f=obj.nextFloat();

         System.out.println("value of float variable is "+f);

        d=obj.nextDouble();

            System.out.println("value of double variable is "+d);

        c=obj.next().charAt(0);

         System.out.println("value of char variable is "+c);

       

       

       

   

    }

   

}



Premitive Data types in java









package javaapplication3;



import java.util.Scanner;





public class JavaApplication3

{



 

    public static void main(String[] args)

    {

       byte b=127;

    System.out.println("value of byte variable is "+b);

    short s=32767;

    System.out.println("value of short variable is "+s);

    long l=659685085;

    System.out.println("value of long variable is "+l);

    int i=654654;

    System.out.println("value of int variable is "+i);

    float f=5.323232f;

    System.out.println("value of float variable is "+f);

    double d=543545435.43;

    System.out.println("value of double variable is "+d);

    char c='a';

    System.out.println("value of char variable is "+c);

    boolean bo=true;

    System.out.println("value of boolean variable is "+bo);

   

   

    }

   

}


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 ...