Sort Words on Potential (Ascending)

Program to accept a sentence which is terminated by ‘.’ or ‘?’ or ‘!’ only. Arrange the words in ascending order of their potential.

Word potential is the sum of ASCII value of every character present in the word. For example the word “Code” has potential 67+111+100+101 = 379.

Example: “How do you do?”. The program should sort the sentence according to the word potential thus generating an output “do do How you”.

Java
import java.util.*;
public class SordWordsPA
{
    public static void main(String args[])
    {
        String str="",wrd="",temp="";
        char ch=' ';
        int l=0,pot=0,count=0;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter a sentence ending with '.' or '?' or '!'");
        str=sc.nextLine();
        str=str.trim();
        l=str.length();
        ch=str.charAt(l-1);
        if(!(ch=='.'||ch=='?'||ch=='!'))
        {
            System.out.println("Error! Sentence must be terminated by punctuation");
            System.exit(1);
        }
        for(int i=0;i<l;i++)
        {
            ch=str.charAt(i);
            if(ch==' '||ch=='.'||ch=='?'||ch=='!')
            {
                count++;
            }
        }
        String w[]=new String[count];
        int p[]=new int[count];
        count=0;
        for(int i=0;i<l;i++)
        {
            ch=str.charAt(i);
            if(ch==' '||ch=='.'||ch=='?'||ch=='!')
            {
                w[count]=wrd;
                p[count]=pot;
                wrd="";
                pot=0;
                count++;
            }
            else
            {
                wrd=wrd+ch;
                pot=pot+ch;
            }
        }
        for(int i=0;i<count;i++)
        {
            for(int j=0;j<count-1-i;j++)
            {
                if(p[j]>p[j+1])
                {
                    p[j]=p[j]+p[j+1];
                    p[j+1]=p[j]-p[j+1];
                    p[j]=p[j]-p[j+1];

                    temp=w[j];
                    w[j]=w[j+1];
                    w[j+1]=temp;
                }
            }
        }
        System.out.print("Sorted string: ");
        for(int i=0;i<count;i++)
        {
            System.out.print(w[i]+" ");
        }
    }
}
Java