INPUT: this is my string

OUTPUT: is my this string

I have to arrange words in a sentence according to their length and if two words have the same length then print them alphabetically (the first priority is length).

My incorrect code:

```
import java.util.Scanner;
class accordingtolength
   {
       void main()
       {
           String result="";
           Scanner sc=new Scanner(System.in);
           System.out.println("Enter the String");
           String str=sc.nextLine();
           String arr[]=str.split(" ");
           int l=arr.length;
           for(int i=0;i<l-1;i++)
           {
               String temp=arr[i]+" ";
               String temp1=arr[i+1]+" ";
               int a=temp.length();
               int b=temp1.length();
               if(a==b)
               {
                   int c=temp.compareTo(temp1);
                   if(c>0)
                   result=temp1.concat(temp);
                   else
                   result=temp.concat(temp1);
                }
                else if(a>b)
                result=temp1.concat(temp);
                else
                result=temp.concat(temp1);
            }
            System.out.println(result);
        }
    }

```

I know my code is incorrect so there is no need to attach the output.

Please help.