-6

I'm working on a gradebook program in Java and I ran into a problem with "unreachable code" If somebody could tell me what is causing this issue I'd appreciate it.

     static ArrayList<String> assignments = new ArrayList<String>();
     static ArrayList<String> grades = new ArrayList<String>();

     public static String getAssignment(int a){
         return assignments.get(a);
         return grades.get(a);
     }

It's giving me the error "unreachable code" on return grades.get(a);

2 Answers2

6

You have two return statement, so the second one will never be reached.

Perhaps you intended to add a condition that would determine which of the two return statements should be executed.

Based on your method's name, it should return an assignment, not a grade :

 public static String getAssignment(int a){
     return assignments.get(a);
 }

But that depends on your logic.

Eran
  • 387,369
  • 54
  • 702
  • 768
  • I cant execute 2 return statements at once? They're parallel array lists so what can I do to make it work? – George Guffey Nov 04 '15 at 13:13
  • @GeorgeGuffey A method can only return one value. What do you expect your method to return? – Eran Nov 04 '15 at 13:14
  • 2
    @GeorgeGuffey: Define "make it work". What are you actually trying to *do*? The first `return` statement is "getting an assignment". Which, based on the name of the method, sounds like reasonable behavior. Why is the second `return` statement there? – David Nov 04 '15 at 13:14
-1

I figured it out. Didn't know you could only return 1 thing in a method at once