Print Sub Array In Java
Print Sub Array In Java
Code :
class HelloWorld {
public static void main(String[] args) {
int arr[] = {3,4,5,6,3};
int l = arr.length;
for (int i = 0; i<l;i++){
for (int j = i; j<l ; j++){
for (int k = i; k <= j; k++){
System.out.print(arr[k] + " ");
}
System.out.println();
}
System.out.println();
}
}
}
Output:
3
3 4
3 4 5
3 4 5 6
3 4 5 6 3
4
4 5
4 5 6
4 5 6 3
5
5 6
5 6 3
6
6 3
3
Thanks.
No comments: