Hello! I am learning Java recently. The task is as follows: a person must enter a name, login and password in the console, after which the program should check the login for involvement in a dynamic array and, if it is not there, add it, and if it is, output an error warning.
At startup, an input window opens where the above-mentioned "name", "login" and "password" are quietly entered. However, the program does not check the login for involvement in the array and does not display an error message, as well as it does not display the array fields themselves. I would be grateful for the help!
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class User { public static void main(String[] args) throws IOException { BufferedReader bReader =new BufferedReader(new InputStreamReader(System.in)); String name = bReader.readLine(); String login = bReader.readLine(); String password = bReader.readLine(); UserADD(name,login,password); } public static ArrayList<String> UserADD(String name,String login,String password) { ArrayList <String> users = new ArrayList<String>(); for (int i = 0; i<users.size(); i++) { if (users.contains(login)) { System.out.println("Это имя пользователя уже занято"); } else users.add(name); users.add (login);users.add(password); { System.out.println(users); } } return users; } }
Thank you all very much, but the problem remained. When the second user tries to enter the login of the first one, the program calmly accepts it, ignoring any restrictions and the warning does not appear on the screen. I tried all the options.
users
throughArrayList <String> users = new ArrayList<String>();
. accordingly, it doesn’t run through the loop, because the size is zero ........ plus brackets are not placed as much aselse
....... but in general, as for me, it would be necessary to make a list User. and add exactly the user, with all his data. Well, it is IMHO. - Alexey ShimanskySet
for storing non-repeating values. - I. Perevoz