Array Programs
Ramya K

Ramya K @ramya_kamalasekaran

About: Having 2.5 years of Experience in Software field. After a career gap planning to start my career again

Joined:
Jan 26, 2025

Array Programs

Publish Date: Apr 30
3 0
  1. Printing numbers in the order : 1,10,2,9,3,8,4,7,5,6
public class AlternateNumbers {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int j=10;
        for(int i=1;i<=5;i++) {
            System.out.print(i+" "+j+" ");
            j--;
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

2.Using array Printing numbers in the order : 1,10,2,9,3,8,4,7,5,6

public class Alternatenumberpattern {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
int[] a= {1,2,3,4,5,6,7,8,9,10};
int n=a.length;
int m=n-1;//last index
for(int i=0;i<n/2;i++) {
    System.out.print(a[i]+" "+a[m-i]+" ");
}
    }

}
Enter fullscreen mode Exit fullscreen mode

3.Using array Printing numbers in the order : 1 -1 1 -1 1 -1 1 -1

public class Patternalternative0and1 {
    public static void main(String[] args) {

        int[] a= {1,1,1,1,-1,-1,-1,-1}; 
        int n=a.length;
        int m=n-1;//last index
        for(int i=0;i<n/2;i++) {
            System.out.print(a[i]+" "+a[m-i]+" ");
        }

    }
}
Enter fullscreen mode Exit fullscreen mode

Same way we can do for this array: int[] a= {1,1,1,1,0,0,0,0};

Comments 0 total

    Add comment