Answers for "how to take input in array"

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
3

input array through scanner in java

public static void main (String[] args)
{
    Scanner input = new Scanner(System.in);
    double[] numbers = new double[5];

    for (int i = 0; i < numbers.length; i++)
    {
        System.out.println("Please enter number");
        numbers[i] = input.nextDouble();
    }
}
Posted by: Guest on January-12-2021
1

take array input

arr = list(map(int, input().split()))
Posted by: Guest on August-08-2020
0

how to take array input from user in javascript

// Here we define a array variable to store user input values:
		var arr=[]; 
	/* Then we define a while loop for taking multiple values.
	it takes the value and store the values into an array until 
    the condition is true.But when a user didn't give a value 
    or just give 'q'value short for quit then it breaks the loop 
    and logs  the array into a console interface of webpage.*/
		while(true){  
			var input=prompt("Enter the Numbers: ");
			if(input== null || input== 'q')
			{
				break;
			}
			arr.push(Number(input));
		}
		console.log(arr);
Posted by: Guest on August-03-2021

Code answers related to "how to take input in array"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language