Answers for "array user input"

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
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 "Java"

Java Answers by Framework

Browse Popular Code Answers by Language