Answers for "for loops for arrays java"

1

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] + " " );
        }
Posted by: Guest on August-04-2021
1

java array loop

public class Test {
    public static void main(String args[]) {
        String string = args[0];
        System.out.println("last character: " +
                           string.substring(string.length() - 1)); 
    }
}
Posted by: Guest on October-15-2020
0

how to use for loop for array in java

// Java program to iterate over an array 
// using for loop 
import java.io.*; 
class GFG { 
  
    public static void main(String args[]) throws IOException 
    { 
        int ar[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; 
        int i, x; 
  
        // iterating over an array 
        for (i = 0; i < ar.length; i++) { 
  
            // accessing each element of array 
            x = ar[i]; 
            System.out.print(x + " "); 
        } 
    } 
}
Posted by: Guest on May-08-2020
0

for loop in java as long as array

for(i = 0; i < arrayName.length; i++{
  	//print statement will output current index's value
 	System.out.println(arrayName[i]); 
}
Posted by: Guest on October-29-2020
0

java loop array

3 1
2 3
Posted by: Guest on June-03-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language