oop - 2 elements in 1 v.add vector java -
For example, I'm calling a scanner from the user. And when I display vector output, these 2 inputs are displayed in 2 lines. Can these two elements be placed in the same vector? The display will be vector: Anyway, in the same vector Please help: ( First, do not use From Using Loop: Double Second = sc.nextDouble (); Double Multiplayer = sc.nextDouble (); V.add (second); V.add (multiplayer);
For example input second 5.0 input multiplayer is 1.4.
5.0 1.4
5.0 to make like 1.4?
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:
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 ("[\\ [\\],]", ""));
For
(double e: v) system.out.print (e); System.out.println ( );
Comments
Post a Comment