如何通过更改if语句来缩短代码,以及如何解决无法修复的代码错误

时间:2019-12-01 06:28:21

标签: java

我想知道如何缩短我的代码并修复它,因为我对Java的了解还不是很好,并且如果有人可以帮助您,谢谢


    String emotion [] = new String [10];
    emotion [0] = "Happy";
    emotion [1] = "Sad";
    emotion [2] = "Vibing";
    emotion [3] = "Trapping";  
    emotion [4] = "Ambationz";
    emotion [5] = "Anxious";
    emotion [6] = "Positive";
    emotion [7] = "Scared"; 
    emotion [8] = "Worried"; 
    emotion [9] = "Focused";
    for(int i = 0; i <  emotion.length; i++){
      System.out.println(emotion[i]);
    }

  //My Method for finding the user input and matching it with their song 
   public static String songfinder( String w ) 
    {
      if(w.equals("Happy"));
        return "https://www.youtube.com/watch?v=ZbZSe6N_BXs";
      (w.equals("happy"));
        return "https://www.youtube.com/watch?v=ZbZSe6N_BXs";
      if(w.equals("Sad"));
       return " https://www.youtube.com/watch?v=pgN-vvVVxMA"; 
      if(w.equals("sad"));
        return " https://www.youtube.com/watch?v=pgN-vvVVxMA";
      if(w.equals("Vibing"));
        return "https://www.youtube.com/watch?v=e2qG5uwDCW4";
     if(w.equals("vibing"));
        return "https://www.youtube.com/watch?v=e2qG5uwDCW4";  
      if(w.equals("Trapping"));
        return "https://www.youtube.com/watch?v=XuEx6lNHZjM";
        if(w.equals("trapping"));
       return"https://www.youtube.com/watch?v=XuEx6lNHZjM";
       if(w.equals("Ambationz"));
         return "https://www.youtube.com/watch?v=cQZqPi1aHNo";
       if(w.equals("ambationz"));
       return "https://www.youtube.com/watch?v=cQZqPi1aHNo";
       if(w.equals("Positive"));
       return "https://www.youtube.com/watch?v=h4UqMyldS7Q";
       if(w.equals("positive"));
       return"https://www.youtube.com/watch?v=h4UqMyldS7Q";  
       if(w.equals("Scared"));
         return"https://www.youtube.com/watch?v=CtdsvvMjJ0I";
       if(w.equals("scared"));
       return"https://www.youtube.com/watch?v=CtdsvvMjJ0I";
       if(w.equals("Worried"));
       return "https://www.youtube.com/watch?v=L3HQMbQAWRc";
       if(w.equals("worried"));
       return"https://www.youtube.com/watch?v=L3HQMbQAWRc";
       if(w.equals("Focused"));
         return"https://www.youtube.com/watch?v=hHW1oY26kxQ";
      if(w.equals("focused"));
       return"https://www.youtube.com/watch?v=hHW1oY26kxQ";
      }
}

im接受用户输入并使用与我的字符串数组中相同的单词匹配用户答案,但是有一种方法可以执行相同的操作,但是没有if语句

0 个答案:

没有答案