Вот алгоритм, но у меня возникли трудности с процессом расшифровывать :Поиск массив для курса
set flag equal to false
set index equal to 0
WHILE(index is less than number of courses in array AND flag == false)
extract substring
IF(string1.equals(string2) == true) THEN //course found
set flag to true
ELSE
increment index
END IF
END WHILE
IF flag == false THEN
display message the course name was not found
ELSE
course name found at position index
END IF
А вот мой код:
public void searchCourse(String courseName)
{
int index;
String extract;
boolean notFound = false;
index = 0;
while(index < SIZE)
{
extract = schedule[index].charAt(0,6);
if (courseName == extract){
}
else {
index ++;
}
if (notFound == false){
System.out.println("Course Not Found");
}
else{
System.out.println("Course Found at: " + index);
}
}
}
Где вы обновляя значение NotFound? В вашем коде всегда установлено значение false, и оно никогда не изменяется. –
Является '' '' '' '' '' '' '' String [] '' '? '' 'charAt''' не имеет перегрузки, которая принимает 2 целых числа. –
Также смотрите: [Как сравнить строки в Java?] (Http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) –