+ 7

How to pass numbers entered by user in the variable length arguments in java

I want to pass the numbers directly into varargs in a function by user input directly ie without using any array . Is there any way .

28th Feb 2019, 2:39 PM
Doggy
Doggy - avatar
3 odpowiedzi
+ 5
Thanks for the answer
1st Mar 2019, 10:44 AM
Doggy
Doggy - avatar
+ 3
Hello, let me see if I understood your question correctly: Do you want to ask the user directly for input and then store that in a variable? If so, this is one solution: //Import the Scanner class. import java.util.Scanner; //Get a new Scanner object. Scanner input = new Scanner(System.in); //Create your variable, prompt the user for input and store it. String test = input.next(); //If it's an integer: int test = input.nextInt(); Note: you can ask for multiple user input by (for example) creating a 'for' loop and asking the user for input inside said loop. Hope that helps!
1st Mar 2019, 10:30 AM
Marcia
Marcia - avatar
+ 3
But i actually want to know about passing values directly to variable length arguments through user input...
1st Mar 2019, 10:46 AM
Doggy
Doggy - avatar