Я разработал код, который будет запрашивать у пользователя 10 названий песен (которые будут храниться в массиве), а затем продолжительность этих песен (также в массив), и, наконец, они могут искать и удалять песню из своего списка.Если оператор печатает часть «else», даже если она правильная
Однако, когда я запускаю раздел поиска и удаления, программа запускает все мои инструкции if. У меня есть «еще», так что если они будут искать песню, которой нет в списке, она скажет «извините» и вернет их к началу. Но он продолжает работать, даже если они выполняют поиск правильного названия песни. Может кто-нибудь помочь?
import java.util.Scanner;
/**
* Created by IntelliJ IDEA.
* Date: 25/02/2015
* Time: 13:37
* UPDATE COMMENT ABOUT PROGRAM HERE
*/
public class Songs
{
static final int SIZE=10;
static String songTitle [] = new String[SIZE];
static Scanner keyboard = new Scanner(System.in);
static double duration[]=new double[SIZE];
static int choice;
static String searchSong;
public static void menu()
{
System.out.println("Please chose from the options below");
System.out.println("1) Enter Song Titles **DO FIRST**");
System.out.println("2) Enter duration of songs **DO SECOND**");
System.out.println("3) Search and remove **DO THIRD**");
choice=keyboard.nextInt();
switch(choice)
{
case 1:
setSongTitle();
menu();
case 2:
duration();
menu();
case 3:
searchRemove();
default:System.out.println("Sorry try again");
menu();
}//switch
}//menu
public static void setSongTitle()
{
for(int count=0;count<SIZE;count++)
{
System.out.println("Please enter your song title number " + (count + 1) + " below..");
songTitle[count]=keyboard.next();
}//setSongTitle();
System.out.println("Here are your songs");
for(int count=0;count<SIZE;count++)
{
System.out.println(songTitle[count]);
}//for
}//setSongTitle
public static void duration()
{
for(int count=0;count<SIZE;count++)
{
System.out.println("Please enter the duration of the song " +songTitle[count] + " below...");
duration[count]=keyboard.nextDouble();
}//for
for(int count=0;count<SIZE;count++)
{
System.out.println(duration[count]);
}//for
}//duration
public static void searchRemove()
{
System.out.println("Please enter a song title you would like to remove");
searchSong=keyboard.next();
for(int count=0;count<SIZE;count++)
{
if(searchSong.equals(songTitle[count]))
{
System.out.println("Song " +songTitle[count] + " is now removed from the list");
System.out.println("The duration of " + duration[count] + " for song " +songTitle[count] + " is now removed from the list");
duration[count]=0;
songTitle[count]=null;
}//if
else
{
System.out.println("Sorry your search has not been found");
searchRemove();
}//else
}//for
}
public static void main(String[] args)
{
menu();
}//main
}//class