int [10] array_int=new int [10];
array_int[0]=0;
array_int[1]=1;
array_int[2]=2;
array_int[3]=3;
array_int[4]=4;
array_int[5]=5;

question is:
how to print in circular manner starting from the middle(index is 2) that is
output :

2 3 4 5 0 1 .

Loop with an index variable that starts from 2, but then when you increment it test if it is >= (length of the array), in which case set it back to 0.

ok
i tried wat u mentioned

import java.util.LinkedList;
import java.util.ListIterator;
import java.io.*;
public class llist {


    public static void main(String[] args) {
        int[] arr ;
        arr=new int[10];
        arr[0]=1;
        arr[1]=2;
        arr[2]=3;
        arr[3]=4;
        arr[4]=5;
        int i;
        for( i=2;i<=5;i++){

        System.out.println(arr[i]);
        }
        if(i==6){
            i=0;
            System.out.println(arr[i]);
            }
        if(i==0){
            i=1;
            System.out.println(arr[i]);
        }


    }

}

is this correct?
but wat if i want to print array from the index 3 or 4 the if condition wat i have mentioned will b executed no matter wat.

Edited 3 Years Ago by Reverend Jim: Fixed formatting

I can't give you a complete homework solution, but here's some pseudo-code that shows how to approach it

int offset = 2;  // this is the first element to print, 0 - (length of array -1
for i= 0 to (length of array -1)    // this controls how many numbers to print
   print array[offset]
   offset = offset + 1
   if (offset >= (array length)) offset = 0
}

Museful: nobody still followed this thread, it's ancient, dead and marked as 'Solved'. no reason to revive it.

This question has already been answered. Start a new discussion instead.