fork download
  1. import java.util.*;
  2.  
  3. class GFG {
  4.  
  5. // The main function that prints the
  6. // arrangement with the largest value.
  7. // The function accepts a vector of strings
  8. static void printLargest(Vector<String> arr){
  9.  
  10. Collections.sort(arr, new Comparator<String>(){
  11.  
  12. // A comparison function which is used by
  13. // sort() in printLargest()
  14. @Override
  15. public int compare(String X, String Y) {
  16.  
  17. // first append Y at the end of X
  18. String XY=X + Y;
  19.  
  20. // then append X at the end of Y
  21. String YX=Y + X;
  22.  
  23. // Now see which of the two formed numbers
  24. // is greater
  25. return XY.compareTo(YX) > 0 ? -1:1;
  26. }
  27. });
  28.  
  29. Iterator it = arr.iterator();
  30.  
  31. while(it.hasNext())
  32. System.out.print(it.next());
  33.  
  34. }
  35.  
  36. // driver program
  37. public static void main (String[] args) {
  38.  
  39. Vector<String> arr;
  40. arr = new Vector<>();
  41.  
  42. //output should be 6054854654
  43. arr.add("54");
  44. arr.add("546");
  45. arr.add("548");
  46. arr.add("60");
  47. printLargest(arr);
  48.  
  49. // output should be 777776
  50. /* arr.add("7");
  51.   arr.add("776");
  52.   arr.add("7");
  53.   arr.add("7");
  54.   */
  55.  
  56. //output should be 998764543431
  57. /*arr.add("1");
  58.   arr.add("34");
  59.   arr.add("3");
  60.   arr.add("98");
  61.   arr.add("9");
  62.   arr.add("76");
  63.   arr.add("45");
  64.   arr.add("4");
  65.   */
  66. }
  67. }
Compilation error #stdin compilation error #stdout 0.03s 16792KB
stdin
Standard input is empty
compilation info
prog.cpp:14:9: error: stray ‘@’ in program
         @Override
         ^
prog.cpp:1:1: error: ‘import’ does not name a type
 import java.util.*;
 ^~~~~~
prog.cpp:8:30: error: ‘Vector’ has not been declared
     static void printLargest(Vector<String> arr){
                              ^~~~~~
prog.cpp:8:36: error: expected ‘,’ or ‘...’ before ‘<’ token
     static void printLargest(Vector<String> arr){
                                    ^
prog.cpp:37:12: error: expected ‘:’ before ‘static’
     public static void main (String[] args) {
            ^~~~~~
prog.cpp:37:30: error: ‘String’ has not been declared
     public static void main (String[] args) {
                              ^~~~~~
prog.cpp:37:39: error: expected ‘,’ or ‘...’ before ‘args’
     public static void main (String[] args) {
                                       ^~~~
prog.cpp:67:1: error: expected ‘;’ after class definition
 }
 ^
prog.cpp: In static member function ‘static void GFG::printLargest(int)’:
prog.cpp:10:9: error: ‘Collections’ was not declared in this scope
         Collections.sort(arr, new Comparator<String>(){
         ^~~~~~~~~~~
prog.cpp:10:26: error: ‘arr’ was not declared in this scope
         Collections.sort(arr, new Comparator<String>(){
                          ^~~
prog.cpp:10:35: error: ‘Comparator’ does not name a type
         Collections.sort(arr, new Comparator<String>(){
                                   ^~~~~~~~~~
prog.cpp:10:46: error: ‘String’ was not declared in this scope
         Collections.sort(arr, new Comparator<String>(){
                                              ^~~~~~
prog.cpp:10:54: error: expected primary-expression before ‘)’ token
         Collections.sort(arr, new Comparator<String>(){
                                                      ^
prog.cpp:29:5: error: ‘Iterator’ was not declared in this scope
     Iterator it = arr.iterator();
     ^~~~~~~~
prog.cpp:31:11: error: ‘it’ was not declared in this scope
     while(it.hasNext())
           ^~
prog.cpp:32:9: error: ‘System’ was not declared in this scope
         System.out.print(it.next());
         ^~~~~~
prog.cpp: In static member function ‘static void GFG::main(int*)’:
prog.cpp:39:9: error: ‘Vector’ was not declared in this scope
         Vector<String> arr;
         ^~~~~~
prog.cpp:39:16: error: ‘String’ was not declared in this scope
         Vector<String> arr;
                ^~~~~~
prog.cpp:39:24: error: ‘arr’ was not declared in this scope
         Vector<String> arr;
                        ^~~
prog.cpp:40:19: error: ‘Vector’ does not name a type
         arr = new Vector<>();
                   ^~~~~~
prog.cpp:40:26: error: expected primary-expression before ‘>’ token
         arr = new Vector<>();
                          ^
prog.cpp:40:28: error: expected primary-expression before ‘)’ token
         arr = new Vector<>();
                            ^
stdout
Standard output is empty