lopp array java
For(<DataType of array/List><Temp variable name> : <Array/List to be iterated>){
System.out.println();
//Any other operation can be done with this temp variable.
}
lopp array java
For(<DataType of array/List><Temp variable name> : <Array/List to be iterated>){
System.out.println();
//Any other operation can be done with this temp variable.
}
loop through array java
public class HelloWorld {
public static void main(String[] args) {
// init array
String[] family = new String[] {"Member1", "Member2", "Member3", "Member4", "Member5"};
// print array
for(String name : family)
{
System.out.println(name);
}
}
}
enhanced for loop java
class AssignmentOperator {
public static void main(String[] args) {
char[] vowels = {'a', 'e', 'i', 'o', 'u'};
// foreach loop
for (char item: vowels) {
System.out.println(item);
}
}
}
loop through array java
import java.util.*;
public class HelloWorld {
public static void main(String[] args) {
// you can define the type of list you want to init - String int etc inside <yourType> eg. <String>
List<String> family = new ArrayList();
family.add("Member1");
family.add("Member2");
family.add("Member3");
family.add("Member4");
family.add("Member5");
// print array
for(String name : family)
{
System.out.println(name);
}
}
}
Java loop array
Scanner scanner = new Scanner( System.in );
int n = scanner.nextInt();
int[] a=new int[ n + 1 ];
for( int k = 1; k <= n; k ++ ){
a[ k ] = scanner.nextInt();
}
Arrays.sort( a );
for( int k = 1; k <= n; k ++ ){
System.out.print( a[k] + " " );
}
java loop array
3 1
2 3
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us