Hello peeps. I have a problem with some code I'm working on. Every thing is working pretty well except for this while loop I'm doing. What the while loop is testing is whether the the two elements in the array are equal to each other. When I test the code, they are indeed equal, but the while loop doesn't compute. I even step through in debug mode; they are indeed equal. Here's my code:
Any help would be much appreciated as usual.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
public class Internship2 {
static BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
ArrayList<Integer> employeeID, lonEmployeeID, stockEmployeeID;
Set<Integer> set;
final int MAX_TEAM = 2;
String[] team = new String[MAX_TEAM];
int numTeams, count = 0;
System.out.println("Number of teams? ");
numTeams = Integer.parseInt(r.readLine());
while(numTeams < 1 || numTeams > 10000){
System.out.println("Number of teams cannot be less than 1 or greater than 10,000. Try again.");
System.out.println("Number of teams? ");
numTeams = Integer.parseInt(r.readLine());
}
employeeID = new ArrayList<Integer>(numTeams);
lonEmployeeID = new ArrayList<Integer>(numTeams);
stockEmployeeID = new ArrayList<Integer>(numTeams);
for(int i = 0; i < numTeams; i++){
System.out.println("Enter the employee ID for Stockholm & London team " + Integer.toString(i));
team = r.readLine().split(" ");
/**
* Doesn't compute? Why?
*/
while(team[0] == team[1]){
System.out.println("Employee numbers cannot be the same. Try again.");
System.out.println("Enter the employee ID for Stockholm & London team " + Integer.toString(i));
team = r.readLine().split(" ");
}
/**
*
*/
employeeID.add(Integer.parseInt(team[0]));
employeeID.add(Integer.parseInt(team[1]));
while(Integer.parseInt(team[0]) < 1000 || Integer.parseInt(team[0]) > 1999 ){
System.out.println("Stockholm employee ID cannot be less than 1,000 or greater than 1,999. Re-enter Stockholm employee ID: ");
team[i] = Integer.toString(Integer.parseInt(r.readLine()));
employeeID.add(i, Integer.parseInt(team[0]));
}
while(Integer.parseInt(team[1]) < 2000 || Integer.parseInt(team[1]) > 2999){
System.out.println("London employee ID cannot be less than 2000 or greater than 2999. Re-enter London employee ID: ");
team[i+1] = Integer.toString(Integer.parseInt(r.readLine()));
employeeID.add(i+1, Integer.parseInt(team[1]));
}
}
for(int j = 0; j < numTeams; j++){
stockEmployeeID.add(j, employeeID.get(j*2));
lonEmployeeID.add(j, employeeID.get((j*2) +1));
}
set = new HashSet<Integer>(employeeID);
//This is totally wrong, but how do I count or do something for the duplicats in the array list.
if(set.size() < employeeID.size()){
System.out.println("Duplicate");
}
}
}
Any help would be much appreciated as usual.