java - How to prevent duplicate user entries into an array? -


this question has answer here:

the point ask user input name. then, another. , store in array. then, if user enters duplicate name, should print line saying, please enter name. here code(so far...also please point out syntax errors..much appreciated...also no hashsets or linkedhashsets because haven't covered in class yet):

import java.util.scanner import java.util.arrays import java.util.arraylist  class noduplicates  {      static final int max = 5; public static void main(string[] args);       scanner input = new scanner(system.in); int     num = 0; float   total = 0; float[] array = new float [max]; string[] name = new string [max];       // read , store marks, (only store) while (num < max) {      system.out.println("enter name");     name[num] = input.nextline();     system.out.println("enter name");     name[num] = input.nextline();     arrylist.contains("name"); 

either loop through array before adding name, or use arraylist , check if name exists using method arraylist.contains("name");.

also may use linkedhashset in answer here.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -