oop - 2 elements in 1 v.add vector java -


For example, I'm calling a scanner from the user. Double Second = sc.nextDouble (); Double Multiplayer = sc.nextDouble (); V.add (second); V.add (multiplayer);

And when I display vector output, these 2 inputs are displayed in 2 lines. Can these two elements be placed in the same vector? For example input second 5.0 input multiplayer is 1.4.

The display will be vector:

  5.0 1.4   

Anyway, in the same vector

  5.0 to make like 1.4?   

Please help: (

First, do not use Vector Use an ArrayList (see why this).

  list & lt; double & gt; v = new arrelist & lt ; Double & gt; (); v.add (5.0); v.add (1.4);   
  • toString () of the list Usage:

    From v.toString () to [5.0, 1.4] . As you can see that some "extra characters" , ] , , to delete them. You can replace replaceAll with [\\ [ \],] by calling .

      system.out.println (v.toString (). ReplaceAll ("[\\ [\\],]", ""));    
  • Using Loop:

     For  (double e: v) system.out.print (e); System.out.println ( );      

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -