write a program in java asking the user to input an array and print it.
Answers
Answered by
4
Hey There!!
Here's your code:
import java.util.Scanner;
public class Array
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of elements of array: ");
int len = sc.nextInt();
System.out.println();
String str[] = new String[len];
for(int i=0;i<len;i++)
{
System.out.print("Enter Element Number "+(i+1)+": ");
str[i] = sc.next();
}
System.out.println();
System.out.println("The Array is: \n");
for(int i=0;i<len;i++)
{
System.out.println(str[i]);
}
}
}
Hope it helps
Purva
Brainly Community
Here's your code:
import java.util.Scanner;
public class Array
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of elements of array: ");
int len = sc.nextInt();
System.out.println();
String str[] = new String[len];
for(int i=0;i<len;i++)
{
System.out.print("Enter Element Number "+(i+1)+": ");
str[i] = sc.next();
}
System.out.println();
System.out.println("The Array is: \n");
for(int i=0;i<len;i++)
{
System.out.println(str[i]);
}
}
}
Hope it helps
Purva
Brainly Community
denifer:
no no...function argument..
Answered by
1
import java.util.Arrays;
import java.util.Scanner;
public class AcceptPrintArray {
public static void main(String[ ] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the length of the Array - ");
int[ ] array = new int[sc.nextInt( )];
System.out.println("Enter the elements - ");
for (int i = 0; i < array.length; i++)
array[i] = sc.nextInt( );
System.out.println("Array - " + Arrays.toString(array));
}
}
Similar questions