Tuesday 15 June 2010

java - Use while loop to add many objects to arraylist -


Take an introduction course in Java using the blues.

Account

Strong> It is easy to add an object to the array list using the loop for a while, although the blues inspires you to choose an account.

I do not know how to automate this process, try something with it:

  Add Public Zero MultiPointPoints () {reader = new InputReader (); System.out.println ("How many accounts do you want to add?"); Int accountsTouad = integer .presscent (reader.jet input); While (accountsToAdd> gt; 0) {System.out.println ("Which account do you want to add?"); String accountToode = ReaderGetInput (); BankAccounts.add (accountToAdd); AccountsToAdd--; }}   

Which clearly does not work InputReader () is a private supply class that uses scanners to collect strings.

I'm sure this is an easy way to do what I'm getting but I can not find it ... I don? T denote the user for input of something, blues has Always do it automatically

  import java.util.ArrayList; Import java.util.Scanner; Public Class Some {/ ** * @ Ultimate Argus * / Public Static Wide Men (string [] Args) {Arrestist & lt; Aclass & gt; List = New Arrestist & lt; Aclass & gt; (); String first, second; Scanner Scanner = New Scanner (System.in); Repeat Int; System.out.println ("How many items do you want to enter?"); Repeat = scanner.xit (); {System.out.println ("Enter your first parameter") for (int i = 0; i & lt; repeat; i ++); First = scanner.xt (); System.out.println ("Enter your second parameter"); Second = scanner.xt (); Aclass temp = new avalose (first, second); // This array will be inserted into list.add (temp); }}} Class ecloss {private string something, apple; Public eccles (string straight 1, string str 2) {anything = str1; Amales = straw 2; }}   

In this case your 'aClass' is your account class and the list is your backends strictly. You obviously need to change the parameters to match your account class, but in this way You will apply it.

No comments:

Post a Comment