Computer Science, asked by denifer, 1 year ago

write a program in java asking the user to input an array and print it.

Answers

Answered by QGP
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


denifer: no no...function argument..
QGP: So, I take input as:
denifer: the program will ask the user
QGP: public static void main(int n1, int n2,int n3) ??/
denifer: leave
QGP: I can help. I just need to know what exactly do you need
denifer: actually i had done it
denifer: so leave
QGP: Okay Sure.
denifer: but tysm
Answered by Oreki
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