java - How to pass the scanner number to an ArrayList -


My method is working fine !! Instead of putting numbers in the form of my code, I am trying to get information from the user. There is no way I can get numbers without storing them in different variables! Thank you. import java.util. *; Public category interleave {public static zero main (string [] args) {scanner console = new scanner (System.in); System.out.println ("Welcome to the Interlave Program!"); Println (); System.out.print ("How many numbers array 1: ="); Int array1 = console.nextInt (); For (int i = 0; i & lt; array 1; i ++) {System.out.print ("Please enter nubmers: ="); Int num = console.nextInt (); } ArrayList & lt; Integer & gt; A1 = new arreelist & lt; Integer & gt; (); A1.add (10); A1.add (20); A1.add (30); Println (); System.out.print ("How many numbers array 2: ="); Int array2 = console.nextInt (); {System.out.print ("Please enter Enmbank: =") for (int i = 0; i & lt; array2; i ++); int num2 = console.nextInt (); } ArrayList & lt; Integer & gt; A2 = New Arrestist & lt; Integer & gt; (); A2.add (4); A2.add (5); A2.add (6); A2.add (7); A2.add (8); Println (); Println (A1); Println (A2); Interleave (A1, A2); // parameters system.out.println (a1); } // Main Public Stable Zero Interface (Interval> List 1, Arrayist & lt; Integer & gt; List 2) {end size} List 1 list = 1.size (); // array size S size // list 2 = list2.size (); // ArrayList of the shape array & lt; Integer & gt; temp = new arreelist & lt; Integer & gt; (); // (for int index = 0; index and lieutenant; list 1 sized (index; ++) // copy elements fom list 1 tmp.ed (index, list 1.jet (index)); (Int index = 0; index and lieutenant; list 2.size (); index ++) // copy allents from list 2 tempe. Ed (index, list 2.jet (index)); Int tempSize = temp.size (); // get temporary array size temp.clear (); // clear tepm array if (list1.size ()> gt2 list2.size ()) {for (index index = 0, list1Index = 0, list2Index = 0; index

  1. create
  2. Every time you need to add a number, call list.add (console.nextInt ())
  3. call mylist, when you do, Or set it to a new array list.

    Just be careful about the different exceptions that can be thrown and try to catch them so that the user will have to type again until he is valid.

Comments

Popular posts from this blog

c# - passing input text from view to contoller with FacebookContext using Facebook app -

ios - Does Core Data autoupdate a many to many relationship on saving -

Calling a C++ function from C# by passing a string with variable size to it -