How to print array without using loop in java is frequently asked question in interview. We can print array without using any loop. For this purpose we will use Arrays's method toString().
package com.javaproficiency;
import java.util.Arrays;
public class PrintArray {
//print array without using loop in java
public static void main(String[] args) {
int [] arr = {15,60,32,33,12};
System.out.println(" Print array ="+ Arrays.toString(arr));
char [] crr = {'A','B','C','D','E','F'};
System.out.println(" Print Array ="+ Arrays.toString(crr));
}
}
Output:
Print array =[15, 60, 32, 33, 12]
Print Array =[A, B, C, D, E, F]
package com.javaproficiency;
import java.util.Arrays;
public class PrintArray {
//print array without using loop in java
public static void main(String[] args) {
int [] arr = {15,60,32,33,12};
System.out.println(" Print array ="+ Arrays.toString(arr));
char [] crr = {'A','B','C','D','E','F'};
System.out.println(" Print Array ="+ Arrays.toString(crr));
}
}
Output:
Print array =[15, 60, 32, 33, 12]
Print Array =[A, B, C, D, E, F]
import java.util.Scanner;
ReplyDeleteclass Demo
{
static int[] a={1,2,3,4,5,6,7,8};
public static void main(String[] args)
{
Array(0);
}
public static void Array(int x)
{
System.out.println(a[x]);
Array(++x);
}
}
import java.util.Scanner;
ReplyDeleteclass Demo
{
static int[] a={1,2,3,4,5,6,7,8};
public static void main(String[] args)
{
Array(0);
}
public static void Array(int x)
{
System.out.println(a[x]);
Array(++x);
}
}
Nice blog post, Thanks a lot providing such a clear explanation.
ReplyDeleteRegards,
Java Training
Learn Java Online
Online Java Training
Best Java online Training Institutes in Hyderabad
Best Java Training Institutes in Hyderabad
Best Institutes for Java
Java Institutes in Hyderabad
Best Institutes for Java in Hyderabad
Learn Java