Enhanced for loop in java with example

Enhanced for loop is simple version of for loop for java arrays

Syntax:-

for(datatype variable : array_name)
{
body of loop
}

Example:-
for(int i : value)

variable is required to hold element of array.
datatype is used for declaring variable data type.
array_name is used to defined which array is using enhanced for loop.

Example:-

import java.util.Scanner;

class group{

public static void main(String arng[]){

int value[]= new int[5];

Scanner data = new Scanner(System.in);

float sum =0;

System.out.println("Enter 5 element of array" );

// Enhanced for loop

for(int i : value)
{

i = data.nextInt();

sum = sum+i;

}

System.out.println("Average of array element");
sum = sum/value.length;
System.out.println(sum);

}

}

Here value is array name 




Previous Code:-
Length function for array

List Code:-
Java codes

Next Code:-


Java Programs:-
List of Java Programs

13 Comments

  1. Your good knowledge and kindness in playing with all the pieces were
    very useful. I don’t know what I would have done if I had not
    encountered such a step like this.


    java Training in Bangalore



    java training in chennai

    ReplyDelete
  2. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog. 
    Selenium Training in Chennai

    ReplyDelete
  3. Your new valuable key points imply much a person like me and extremely more to my office workers. With thanks from every one of us.

    Best AWS Training in Chennai | Amazon Web Services Training in Chennai

    Best AWS Training in Chennai | Amazon Web Services Training in Chennai

    ReplyDelete
  4. I likable the posts and offbeat format you've got here! I’d wish many thanks for sharing your expertise and also the time it took to post!!
    Click here:
    angularjs Training in online

    Click here:
    angularjs training in annanagar
    Click here:
    angularjs training in bangalore
    Click here:
    angularjs training in chennai
    Click here:
    angularjs training in velarchery

    ReplyDelete
  5. It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.

    digital marketing training in tambaram

    digital marketing training in annanagar

    digital marketing training in marathahalli

    digital marketing training in rajajinagar

    Digital Marketing online training


    ReplyDelete
  6. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.


    Devops training in Chennai
    Devops training in Bangalore
    Devops training in Pune
    Devops Online training
    Devops training in Pune
    Devops training in Bangalore
    Devops training in tambaram

    ReplyDelete
  7. I would assume that we use more than the eyes to gauge a person's feelings. Mouth. Body language. Even voice. You could at least have given us a face in this test.
    python training in tambaram | python training in annanagar | python training in jayanagar

    ReplyDelete
  8. Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.
    Online DevOps Certification Course - Gangboard
    Best Devops Training institute in Chennai

    ReplyDelete
  9. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    rpa training in velachery| rpa training in tambaram |rpa training in sholinganallur | rpa training in annanagar| rpa training in kalyannagar

    ReplyDelete
  10. Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated tutorials…

    Java training in Annanagar | Java training in Chennai

    Java training in Chennai | Java training in Electronic city

    ReplyDelete

Add your comments here

Back to Top