import java.util.StringTokenizer;
import java.util.Scanner;
class token
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int sum=0,count=0;
        boolean allIntegers=true;
        String str=sc.nextLine();
        StringTokenizer st=new StringTokenizer(str," ");
        System.out.println("Total Number of tokens:"+st.countTokens());
        st=new StringTokenizer(str," ");
        while(st.hasMoreTokens())
        {
            String token=st.nextToken();
            count++;
            try
            {
              int num=Integer.parseInt(token);
              sum=sum+num;
              System.out.print(num+" ");
            }
        catch(NumberFormatException e)
        {
            allIntegers=false;
            System.out.println();
            System.out.println("non integer is encountered. terminated.");
            return;
        }
        }
        System.out.println();
        if(allIntegers)
        {
        System.out.println("Sum of tokens:"+sum);
        }
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: