Answers for "how to make java method that take an input of an array of integers"

5

how to get an array as input in java

public class TakingInput {

    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);

        System.out.println("enter number of elements");

        int n=s.nextInt();

        int arr[]=new int[n];

        System.out.println("enter elements");

        for(int i=0;i<n;i++){//for reading array
            arr[i]=s.nextInt();

        }

        for(int i: arr){ //for printing array

            System.out.println(i);

        }


    }

}
Posted by: Guest on October-04-2020
0

int array input in java

int[] array = new int[10];
Posted by: Guest on August-09-2021

Code answers related to "how to make java method that take an input of an array of integers"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language