Home > Back-end >  Take a look at this to do? thank you
Take a look at this to do? thank you

Time:09-22

Given the following code compiler error, please find out,
import java.util.*;
Public class Pockets {
Public static void main (String [] args) {
String [] sa={" east "and" west ", "south", "north"};
Sorter s=new Sorter ();
For (String s2: sa) System. Out. Print (s2 + "");
The Arrays. Sort (sa, s);
System.out.println();
For (String s2: sa) System. Out. Print (s2 + "");
}
The class Sorter implements Comparator {
Public int the compare (String a, String b) {
PareTo return b.com (a);
}
}
}
Use two methods to modify the program to compile and run the right: (1) Sorter class is defined as the static inner class, (2) the use of external when creating the Sorter object class a reference,
Finally, using an anonymous inner class to rewrite the program to realize the same function,
Requirements: submit the program code and operation result screenshots,

CodePudding user response:


Please first learn to code,

CodePudding user response:

Main is a static method cannot directly create an inner class inside, so after you polish the inner classes to increase the static can compile and run,
Two way,
1, create a public methods, implementation logic in this aspect, and then the main aspects of new a Pockes object invocation,
2, create the object is modified to: Sorter s=new Pockets () new Sorter ();

CodePudding user response:

static
  • Related